Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel UserForm-->MultiPage-->Array_of_Textbox???

Status
Not open for further replies.

mjpearson

Technical User
Dec 13, 2002
196
US
I'm using Excel and I have built a UserForm. On the UserForm, I've placed a MultiPage. I would like to put 20 Textboxes on each of the pages.

When I drag a textbox to the userform from the toolbox, Excel automatically assigns the name to the new textbox. More specifically, it appends the index number to "TextBox"....e.g. "TextBox5".

Is there a way to make the textboxes into array items?

I'd like to be able to reference the textboxes by an index number rather than a suffix.

e.g. "TextBox(5)" rather than "TextBox5"


mike
 
If you need an array, just create it:
Code:
Dim tbArray(1 To 20) As MSForms.TextBox

Private Sub UserForm_Initialize()
Set tbArray(1) = Me.Controls("TextBox" & 1)
' or
' Set tbArray(1) = TextBox1
' etc
End Sub
For handling events, see my faq707-4976.

combo
 
Thanks Combo,

So, there is no "direct" way to rename the textbox. It looks like VBA doesn't have the means to create the array while instantiating the TB. So, you're advocating that we build a new pointer to the existing box. Kind of an interesting work-around.

Thanks,


mike
 
You can rename the MSForms textbox (the 'properties' window), but you can't create controls array similar to vb.
BTW, you can see that you can call textbox by name, in Controls collection.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top