View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Dynamic Control Creation in VBA

I don't know why you would say it isn't supported since that isn't correct.

In fact you can dynamically create controls on a userform.

From John Walkenbach's site

http://j-walk.com/ss/excel/tips/tip76.htm
Creating a UserForm Programmatically


A simple example:

Private Sub CommandButton1_Click()
Dim tbox As MSForms.TextBox
Set tbox = Controls.Add("Forms.TextBox.1", _
Name:="Textbox5", Visible:=True)
tbox.Top = TextBox1.Top + TextBox1.Height + 10
tbox.Left = TextBox1.Left
tbox.Width = TextBox1.Width
tbox.Height = TextBox1.Height
End Sub

--
Regards,
Tom Ogilvy



"Asif" wrote in message
...
There are 4 text boxes horizontally placed. As soon as the user leaves the
last one, another set of 4 text boxes are created below the original 4 ...
and this continues.

That's how I was envisaging my user form, as I thought it would enhance

the
usablity of the form. And in any case I don't know beforehand how many

such
sets of text boxes the user will need. Now I'm disappointed to know

dynamic
control creation isn't possible in hosted VBA. Is there any alternative

way?

Thanks. ~Asif