Add Button at Run-time in Code

E

ExcelMonkey

I am trying to add a button to a Form in code. When I run the code below the
form shows without a button on it. Why is this?

Dim NewBttn As MSForms.CommandButton

Set NewBttn = UserForm1.Controls.Add("forms.CommandButton.1")
NewBttn.Top = FirstRowSquareTop * Counter
NewBttn.Left = FirstRowSquareLeft * Counter
NewBttn.Width = FirstRowWidth * Counter
NewBttn.Visible = True
'Set NewBttn = Nothing

UserForm1.Show
End Sub
 

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

Top