adding components in VBA

C

chrisdarl

Hi, is there a way that i can add text boxs and labels to my userfor
using coding instead of just using the toolbox?

Can this be done? thanks chris
 
C

Chip Pearson

Chris,

Yes, it can be done. The changes are temporary, though; the
control will disappear when the form is unloaded. For example,
the following will add a text box to Userform1.

Dim TBX As MSForms.TextBox
With UserForm1.Controls
Set TBX = .Add(bstrprogid:="Forms.TextBox.1", _
Name:="MyTextBox", Visible:=True)
TBX.Top = 50
TBX.Left = 100
End With
UserForm1.Show


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
B

Bob Phillips

Alternative approach is to add them at design time, but hide them until you
need them.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top