Adding controls to user form

D

Dave Neve

Hi

I got this bit of code from a recent conversation and aapted it as par a
help page. I have also created a UserForm1 (blank)

But when I run the code, nothing happens.

Sub AddControlToUF()

Dim newControl As Control
Set newControl = UserForm1.Controls.Add("MSForms.CommandButton.1")

End Sub

What's the trick this time please???

Thanks
 
P

Peter Hewett

Hi Dave Neve

THe class specification string is incorrect. Try:

Dim ctlNew As MSForms.Control
Set ctlNew = Me.Controls.Add("Forms.CommandButton.1")

HTH + Cheers - Peter
 

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