Link to home
Start Free TrialLog in
Avatar of Massimo Scola
Massimo ScolaFlag for Switzerland

asked on

How do I apply a property to all controls in a userform?

Hi

I have several controls (especially labels) which I would like to make transparent when the userform is initialized.

How do I loop through all controls and change their properties?

Thanks
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You will need something like this
Sub ModControls()
    Dim ctl As MSForms.Control
    For Each ctl In UserForm1.Controls
        If TypeName(ctl) = "Label" Then
            ctl.BackStyle = fmBackStyleTransparent
        End If
    Next ctl
End Sub

Open in new window

Avatar of Massimo Scola

ASKER

Graham: I get a message that a Object required is required.
Am I missing something?
Hmm. It works OK for me. Which line gives the error?
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fantastic!
Thanks a lot!