Re: Looping through UserForms
Hi Andy,
OK - here goes.
Each form contains controls (text boxes & combo boxes) that have 'Tag' names - these match named ranges (usually single cells) in the workbook.
These 'tag'ged controls represent every designated 'user input' cell that exists in the workbook.
I am trying to generate a file that contains all these user input values, eg. to reconfigure a new workbook at a later date.
Rather than interogating every cell in the workbook, it seemed to be a good idea to use the controls already existing on my forms 'myfrmN' (there is approx. one form per worksheet). So far the only way I have found of accessing these forms is to open each one explicitly, ie.
For Each Ctrl In myForm1.Controls
If Ctrl.Tag <> "" Then
ReDim Preserve myArray3(1, i)
Ctrl.Value = Range(Ctrl.Tag).Value
myStr = Ctrl.Tag
myVal = Range(Ctrl.Tag).Value
myArray3(0, i) = myStr
myArray3(1, i) = myVal
i = i + 1
End If
Next Ctrl
For Each Ctrl In myForm2.Controls
If Ctrl.Tag <> "" Then
ReDim Preserve myArray3(1, i)
Ctrl.Value = Range(Ctrl.Tag).Value
myStr = Ctrl.Tag
myVal = Range(Ctrl.Tag).Value
myArray3(0, i) = myStr
myArray3(1, i) = myVal
i = i + 1
End If
Next Ctrl
Display More
As you can see the code is the same - just the method for accessing the forms is proving difficult via VBA code.
Hope this helps you understand what I am doing a little better?