runtime Control and code in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i want to add runtime command button and want to add click event to this button.

Pls help me out .

Thanx in advance.

Anu
 
Anu,

This goes into a userform:

Public WithEvents cmdButton As MSForms.CommandButton

Sub testit()
Set cmdButton = Me.Controls.Add("Forms.CommandButton.1", "cmdMyButton")
cmdButton.Caption = "Click Me"
End Sub

Private Sub cmdButton_Click()
MsgBox "Hello"
End Sub


Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top