Add Button at Run-time in Code

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
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
 
Back
Top