Dynamic Control Creation in VBA

  • Thread starter Thread starter Asif
  • Start date Start date
A

Asif

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
 
This certainly seems possible to do whats the difficulty? I've created txt box's before on the fly and its worked fine
 
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
 
Back
Top