VBA, give colors to buttons

Hello guys.

I have 15 buttons on a form. Below it is a picture of my form with the buttons.

They are named like:



I would like (with a vba macro) to give the 15 buttons the same colors as the highlight color options in word, like in the picture below
Highlight ColorsAny ideas of how I achieve this?
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
Not sure why this in the JScript Zone.

The BackColor property for a VBA userform Command button is a Long, which can express nearly 17 million colours in RGB format.

The .ColorIndex in an Enum with about 16 values for colours.

Unfortunately, there is no simple automatic way to derive the RGB value from the from the index, i.e. to convert .ColorIndex to .BackColor.

I would advise experimentation, working in Hex.

Red = &H00FF0000
Green = &H0000FF00
Blue = &H000000FF
Yellow =  &H00FFFF00
Mid Grey = &H00777777

Alternatively, some graphics packages will report the colour value at a point, so you could open your jpg there and thus get the values
I don't see BackColor as an option for CommandButton (which could just be me); maybe you'd be best off utilizing a different object type that has BackColor and specifying OnClick as well for the object.
New_AlexAuthor Commented:
Hi Dagesi.

There is a BackColor option for CommandButton in the design Properties window.

It does not have to be a button. A select box could do the same.

How do I change the color of a CommandButton is the main question,,,

Any ideas?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

if you are supposed to use rectangular shape (similar to work as button), here goes the code
With ActiveWorkbook.Sheets(ASheet).Rectangles.Add(280, 30, 160, 30)
    .OnAction = "CODING"
    .Caption = "MAIN MENU"
    .Font.Size = 25
    .Font.Underline = xlUnderlineStyleSingle
    .Name = "CODING"
    .Interior.Color = RGB(255, 255, 255)
    .Border.Color = RGB(255, 255, 255)
End With
karthika_ctsConnect With a Mentor Commented:
Here's another way..

Put textbox over command button caption. Set the backolor of the text box to the color of the
command button, set borders to None. Change the ForeColor of the Text box.

If you use this, don't forget to add
Private Sub Text1_Click()
End Sub

I think I see... I thought you were creating a form in another software (such as Access) that would be similar to Word's color pallette, not that you wanted to create one on a form apparently *in* Word.
New_AlexAuthor Commented:
Thanks GrahamSkan. This is the theory behind colors I needed to know. Then I may use .Jpg image as background with mouse click regions.

Thanks karthika_cts and dagesi as well for the value they added in my thread.

dagesi, that is right. I was looking for a word VBA solution within word.

Take care and
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.