Here's the code that the click event should activate:
Private Sub CommandButton1_Click()
Call BClicked(1)
End Sub
Private Sub CommandButton2_Click()
Call BClicked(2)
End Sub
....and so on. A minimum of 20 buttons, possibly as many as 40.
Here's the code that creates rows and columns of buttons:
Sub Add_Buttons2(aRows, aCols)
bHeight = 42
bWidth = 42
VOffset = bHeight + 3
HOffset = bWidth + 3
StartLeft = (-1 * HOffset) + 2
StartTop = (-1 * VOffset) + 40
a = 1
w = (aCols * (HOffset + 1.3))
If w < 278 Then ' make sure the form is wider than label1 and the two
predefined buttons
w = 278
HOffset = (278 / aCols) - 2
StartLeft = StartLeft - 2
End If
UserForm4.Width = w
UserForm4.Height = (aRows * (VOffset + 6.4)) + 38 ' the 38 accounts for the
yes/no prompt at top of form
Dim myUF As UserForm
Set myUF = UserForm4
Dim myBtn As Control
For b = 1 To aRows '
CurTop = StartTop + (VOffset * b)
For c = 1 To aCols
Set myBtn = UserForm4.Controls.Add("Forms.CommandButton.1")
With myBtn
.Left = StartLeft + (HOffset * c)
.Top = CurTop
.Width = bWidth
.Height = bHeight
.FontSize = 26
.Caption = a
End With
Call Add_Code(Trim$(Str$(a)))
If a >= TotalItems Then
Exit Sub
End If
a = a + 1
Next c
Next b
End Sub
"JLGWhiz" <(E-Mail Removed)> wrote in message
news:A16B2945-5AF6-411F-A022-(E-Mail Removed)...
> It might help to post the code that creates the buttons, plus the click
> event
> code behind the buttons that don't fire. Otherwise, we are whistling in
> the
> wind here.
>
> "Bert" wrote:
>
>> You're right. In the code, it's actually as you have it corrected.
>> ....still won't run, though.
>>
>> "JLGWhiz" <(E-Mail Removed)> wrote in message
>> news:C7A18B8F-6239-409E-BE49-(E-Mail Removed)...
>> > If it is written as posted it won't fire because the sytax is in error.
>> >
>> > Private Sub CommandButton1_Clicked() <<<This is in error
>> > Call Bclicked(1)
>> > End Sub
>> >
>> > Correct syntax is Private Sub CommandButton1_Click()
>> >
>> > The macro call for Bclicked correctly has an argument in parentheses
>> > but
>> > is
>> > the argument valid? If the argument is not valid then that macro will
>> > not
>> > run and you should be getting an error message.
>> >
>> > "Bert" wrote:
>> >
>> >> In Excel 2003, I've created a userform. Then through macros, I add
>> >> commandbuttons. I've already added in the Userform code (using the
>> >> editor)
>> >> which should execute when the buttons are clicked. (There's one
>> >> subroutine
>> >> for each button, e.g.:
>> >> Private Sub CommandButton1_Clicked()
>> >> Call Bclicked(1)
>> >> End Sub
>> >> The problem is, when I click on the commandbuttons generated by the
>> >> macro,
>> >> the none of the subroutines execute. (I do have two commandbuttons
>> >> that
>> >> are
>> >> predefined, and they work fine.)
>> >> Any suggestions why this might be happening?
>> >> Thanks
>> >>
>> >>
>> >>
>>
>>
>>
>
|