|
-
Jan 23rd, 2004, 05:04 PM
#1
Thread Starter
Fanatic Member
events and dynamic control in Excel VBA
i can dynamically add commandbuttons to an excel form. And then I use WithEvents.
I just cannot get the Click event to fire. I can see the list of events in the dropdown for my new control that will be added to the control collection but it won't fire.
Any ideas why?
Code:
Dim WithEvents cmdAdmit As CommandButton
Private Sub UserForm_Click()
Set mycmd = Controls.Add("Forms.CommandButton.1", "cmdAdmit", Visible)
mycmd.Left = 10
mycmd.Top = 100
mycmd.Width = 175
mycmd.Height = 20
mycmd.Caption = "Admit"
End Sub
Private Sub cmdAdmit_Click()
MsgBox "testing 1-2-3"
End Sub
-
Jan 26th, 2004, 05:35 AM
#2
You need to set the same variable name as is declared, i.e. :
VB Code:
Private WithEvents cmdAdmit As msforms.CommandButton
Private Sub UserForm_Click()
Set cmdAdmit = Controls.Add("Forms.CommandButton.1", _
"cmdAdmit", True)
With cmdAdmit
.Left = 10
.Top = 100
.Width = 175
.Height = 20
.Caption = "Admit"
End With
End Sub
Public Sub cmdAdmit_Click()
MsgBox "testing 1-2-3"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|