ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic Control Creation in VBA (https://www.excelbanter.com/excel-programming/284904-dynamic-control-creation-vba.html)

Asif[_3_]

Dynamic Control Creation in VBA
 
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







Nichevo

Dynamic Control Creation in VBA
 
This certainly seems possible to do whats the difficulty? I've created txt box's before on the fly and its worked fine

Tom Ogilvy

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










All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com