UserForm Controls Collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to "capture" all of the controls on a form that are of a
certain type. for example. Change the forecolor of all labels to Blue.

with my naming conventions i could probably do this with some kind of loop
since all my labels' names start with "lab", but i dont know how to identify
them in the controls collection as a specific type of control.
 
Dim Ctl As MSForms.Control

For Each Ctl In Form1.Controls
If TypeName(Ctl) = "Label" Then
'control code here
End If
Next Ctl

RBS
 
Another way:

Dim Ctl As MSForms.Control

For Each Ctl In Userform1.Controls
If TypeOf Ctl is MsForms.Label Then
'control code here
msgbox Ctl.name
End If
Next Ctl


Your original suggestion

for i = 0 to Userform1.controls.count - 1
if instr(1, me.Controls(i).name, "lab", vbTextCompare) = 1 then
msgbox me.controls(i).name
end if
Next
 

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