Chris
Chris

Reputation: 5

Change the font and background color of an Excel CommandBar

I have search online and in this forum for hours trying to find someone with a similar issue, but have been unsuccessful. I am trying to determine how to change the default background color and font color for an Excel CommandBar pop-up. Here is my applicable code:

Public Sub Custom_PopUpMenu_1()
    Dim MenuItem As CommandBar

    Set MenuItem = Application.CommandBars.add(name:=menuName, Position:=msoBarPopup, _
                                               MenuBar:=False, Temporary:=True)

    With MenuItem
        With .Controls.add(type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.name & "'!" & "tbox_Copy"
            .Caption = "&Copy"
        End With '.Controls.add(msoControlButton)
    
        With .Controls.add(type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.name & "'!" & "tbox_Paste"
            .Caption = "&Paste"
        End With '.Controls.add(msoControlButton)
    
        With .Controls.add(type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.name & "'!" & "tbox_Cut"
            .Caption = "Cu&t"
        End With '.Controls.add(msoControlButton)
    
        With .Controls.add(type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.name & "'!" & "tbox_Select"
            .Caption = "&Select"
        End With '.Controls.add(msoControlButton)
    
        With .Controls.add(type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.name & "'!" & "tBox_clear"
            .Caption = "C&lear"
        End With '.Controls.add(msoControlButton)
    End With 'CommandBars.add(menuName, msoBarPopup)
End Sub

Everything works as desired, however, when the pop-up appears the text is white and the background is also white. Therefore unless you are looking very closely for the faint outline of the pop-up window, you will not realize it is present. When I mouse over a particular item (e.g. Copy, Paste, etc.) the background dynamically changes to a dark grey (text remains white) and also highlights in a light green. After I mouse over all of the available options (i.e. msoControlButtons), the background remains dark grey and the pop-up is then fully visible. Thus, the problem is the pop-up is almost invisible when it first appears until you mouse over all of the options and change the individual background of each option to dark grey. I would like the pop-up to have a white background (which it already does, with black text), but I can not figure out how to code this or where the object attributes are I need to change.

Things I've already tried:

  1. Changing the mode of Windows from dark to light and vice-versa: no change in behavior. I am currently running the Dark Theme. I really thought this would fix it, but it did not.
  2. Searching for the background/font color options. There is no .background nor .font option within the .Controls.add(type:=msoControlButton) object. After a control is added, under the CommandBar ("MenuItem" in my case) there is a Controls -> Item1 -> Application -> SmartArtColors. However, I don't think this is the correct place to look and I am not sure how to change it or if I can since it is under the Application class. There are also no other color or font options in the Controls object class. Any insight would be greatly appreciated!

Upvotes: 0

Views: 424

Answers (0)

Related Questions