adding components in VBA

  • Thread starter Thread starter chrisdarl
  • Start date Start date
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
 
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
 
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)
 

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

Back
Top