0

I've got two buttons on my Userform, one drawn in in the userform vba view-object mode, and one that is added with the following code in the sub Userform_Initialize():

Dim Obj As Object
Set Obj = UserForm1.Controls.Add("Forms.CommandButton.1", "commandbuttondone", True)
With Obj
    .Caption = "filled 1n"
    .Left = 550
    .Height = 40
    .Width = 35
    .Top = 5
    MsgBox Obj.name
End With

The first one is responsive when it is clicked. But the one I add/create programmatically, does nothing.

I've tried calling the following codes after clicking the command button commandbuttondone:

1.

Private Sub commandbuttondone_Click()
    MsgBox ("test message")
End Sub

2.

Private Sub commandbuttondone()
    MsgBox ("test message")
End Sub

3.

Sub commandbuttondone_Click()
    MsgBox ("test message")
End Sub

4.

Sub commandbuttondone()
    MsgBox ("test message")
End Sub

But none work. They are all in the "form/module that also houses the userform_initialize sub, as well as the working first button: OKButton_Click()

So I was wondering if there are any suggestions on why it does not display the message box stating "test message"?

5

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.