Excel vba - Adding a command button control at run time

  • Thread starter Thread starter beastofbobmin
  • Start date Start date
B

beastofbobmin

I have this problem that i need to add a new button at runtime at
specific place on the form. this happends when the form button i
pressed . i have no clue on how to tackle this problem as i have neve
before this project tackled vba or vb
can any one help m
 
Here is some code to ad the control, but you still need event code behind it

Dim newButton As MSForms.Control
Set newButton = Me.Controls.Add("Forms.CommandButton.1")
With newButton
.Caption = "newCmd"
.Left = 50
.Top = 100
.Visible = True
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Try something like this

Private Sub CommandButton1_Click(
Dim btn As Contro
Set btn = UserForm1.Controls.Add("Forms.CommandButton.1", "NewButton", True
With bt
.Caption = "New Button
.Accelerator = "N
.Left = 5
.Top = 3
End Wit
End Su

-Brad Vontur
 
put the button on the form. Make its visible property false. At the
appropriate time, change the visible property to true. This is much simpler
than trying to add it at runtime.
 

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