Set Userform Background & ForeColor color

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have a code that changes my sheet background color to a dark blue. (Dark Theme). I would like my userform to match the sheet color.

In the picture below, I manually set the colors, however, i would like to do this by VBA.

1. Userform and All Frames (if more than 1) background colors to blue
2. All Labels and frame forecolors to white

1597489505315.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,
one way maybe

Rich (BB code):
Dim ctrl As Control
    Dim myBackColor As Long
    
    myBackColor = vbBlue
    
   For Each ctrl In Me.Controls
        If TypeName(ctrl) = "Label" Or TypeName(ctrl) = "Frame" Then
            ctrl.BackColor = myBackColor
            ctrl.ForeColor = vbWhite
        End If
    Next
    Me.BackColor = myBackColor

Just assign the actual blue value you require to variable shown in bold


Dave
 
Upvote 0
Great!!! Thank you dmt32 for your help.
 
Last edited:
Upvote 0
Great.. How do I exclude 1 label named lbTitle?


add code shown in BOLD

Rich (BB code):
For Each ctrl In Me.Controls
        If TypeName(ctrl) = "Label" Or TypeName(ctrl) = "Frame" Then
            If Not ctrl.Name = "lbTitle" Then
                ctrl.BackColor = myBackColor
                ctrl.ForeColor = vbWhite
            End If
        End If
    Next

Dave
 
Upvote 0
You saw the post before I answered my question...lol. I was using f TypeName(ctrl) = "Label", But thank you very much for your help. :)
 
Upvote 0
welcome - glad suggestion helped

Dave
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,850
Members
449,345
Latest member
CharlieDP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top