Search code examples
excelbackcolorvba

Excel VBA .BackColor color list


When setting a component color in Excel VBA using the syntax .BackColor, what should I enter to get desired color?

CommandButton.BackColor = 'What should I have here?

Solution

  • Here is a list of official names for colors: https://msdn.microsoft.com/en-us/library/6ys84h69%28v=vs.90%29.aspx.

    When building a userform in excel, in the properties windows, open the drop down window for BackColor. Each color will have a name. "vb" follow by the name of the color you want without spaces will work as valid syntax (have not tested all of the color, could be wrong).

    Just type SystemColorConstants. (including the dot) and you will get the whole list of constants. (Thanks Tom, from reply to question.)

    CommandButton.BackColor = vbButtonFace 'This is default color for command button.