View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default How to iterate through all Text Boxes on a Form?

Hi Ed

Put them into your own new custom collection like this:

Option Explicit

Dim MyTextBoxes As Collection

Private Sub UserForm_Initialize()
Set MyTextBoxes = New Collection
MyTextBoxes.Add Me.TextBox1, "T1"
MyTextBoxes.Add Me.TextBox2, "T2"
MyTextBoxes.Add Me.TextBox3, "T3"
End Sub

Private Sub CommandButton1_Click()
Dim TB As MSForms.TextBox
For Each TB In MyTextBoxes
MsgBox TB.Text
Next
MsgBox MyTextBoxes("T2").Text
MsgBox MyTextBoxes(1).Text
End Sub

HTH. Best wishes Harald

"Ed" skrev i melding
...
I can iterate through all the controls on a UserForm, but I can't find a
"Type" or other property that will let me get just the Text Boxes. Any
help?

Ed