View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ExcelMonkey ExcelMonkey is offline
external usenet poster
 
Posts: 553
Default Add Button at Run-time in Code

Sorry this does work, my width was set incorrectly.

EM

"ExcelMonkey" wrote:

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