Adding commandbutton at run time
I have a userform called userform1 with the code posted below in the code
module.
The userform does not contain any controls and there is nothing else in the
code module.
When I open it with "userform1.show", the commandbutton is added properly.
However, when I click on the command button, the "msgbox 7" is not
displayed.
What do I need to change to get this command button to work after I add it?
Thanks in advance for any help.
Ron
Private Sub UserForm_Initialize()
Dim cmd1 As msforms.CommandButton
Set cmd1 = UserForm1.Controls.Add("Forms.CommandButton.1")
With cmd1
.Name = "cmdOK"
.Caption = "OK"
.Font.Size = 8
.Left = 10
.Width = 40
.Top = 10
.Height = 20
End With
End Sub
Sub cmdOK_Click()
MsgBox 7
End Sub
|