Create Run Time Controls

J

John Krueger

Does anybody know how to create controls during run-time
on a userform in Excel VBA? I actually saw a post on how
to do this once but I can't find it anymore. At the time
I thought, "I'll never need to do that..."

Anyway, I'm trying to use Controls.Add, but I can't figure
out what the first argument (bstrProgID as String) is
supposed to be. I'm assuming that is where I declare the
control type (checkbox, label etc) but I can't figure out
the syntax.

Controls.Add(bstrProgID as String, [Name] , [Visible])

Things I've tried:

Controls.Add("vb.label", "lblLabel1" , True)

Controls.Add("MSForms.CommandButton.1", "cmdButton1" ,
True)


John
 
J

John Krueger

Hey what's the deal with all the spam? I'm getting two
emails every five minutes!!!

This isn't cool? Anybody know what to do???
 
J

John Krueger

The solution to my question is to change
Controls.Add("MSForms.CommandButton.1", "cmdButton1" ,
True)
to

Controls.Add("Forms.CommandButton.1", "cmdButton1" ,
True)

and it will work fine.

Once I got that to work I needed to figure out how to work
with the controls. You can access the value of a run-time
created control by using Controls.Item(index).




-----Original Message-----
Does anybody know how to create controls during run-time
on a userform in Excel VBA? I actually saw a post on how
to do this once but I can't find it anymore. At the time
I thought, "I'll never need to do that..."

Anyway, I'm trying to use Controls.Add, but I can't figure
out what the first argument (bstrProgID as String) is
supposed to be. I'm assuming that is where I declare the
control type (checkbox, label etc) but I can't figure out
the syntax.

Controls.Add(bstrProgID as String, [Name] , [Visible])

Things I've tried:

Controls.Add("vb.label", "lblLabel1" , True)

Controls.Add("MSForms.CommandButton.1", "cmdButton1" ,
True)


John
.
 

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