VBA & Macro Problems

Set a Custom Font Color in Word 2010 VBA

Maira MehtabMaira Mehtab Nov 20, 2026 869 views

Question details

The user needs to set a custom font color in Word 2010 using VBA.

Set a Custom Font Color in Word 2010 VBA
Product
Microsoft Word 2010
Device & OS
not provided
Scenario
Applying a named theme color to selected text through a VBA statement.
Observed behavior
Using a color name such as Orange, Accent 6, Darker 25% in the statement produces an Expected end of statement error.
Before you start

Select the text you want to color and identify the color's red, green, and blue values. In Word, you can inspect a color through Home > Font Color > More Colors > Custom.

Solution 1Recommended

Set the selected font color with RGB in Word VBA

Use numeric RGB values instead of a color name to avoid the VBA syntax error.

The RGB function takes red, green, and blue values from 0 to 255. It applies a fixed color, so it will not automatically change with the document theme.

1
Open the VBA editor

In Word 2010, press Alt+F11, then choose Insert > Module.

2
Enter the macro

In the module, enter: Sub SetFontColor() Selection.Font.Color = RGB(0, 0, 255) End Sub. Replace 0, 0, 255 with the RGB values for your desired color; the example applies blue.

3
Run the macro

Return to the document and select the text. Press Alt+F8, select SetFontColor, and click Run.

Set the selected font color with RGB in Word VBA
Matching a theme color: Check the displayed color's RGB values before substituting them in the macro. A fixed RGB color may not match the theme color after the document theme changes.
Free Microsoft Office alternative

Apply Custom Font Colors in WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility, making it easy to move documents and apply font colors in WPS Writer. It does not fix Word's VBA syntax error.

Choose custom font colors in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for an easier transitionWork with a free, lightweight office suite
QA img-9

Frequently Asked Questions

Why does a named theme color cause a VBA error?

Word VBA does not accept a label such as Orange, Accent 6, Darker 25% as a color value in that statement. Set Selection.Font.Color with RGB(red, green, blue) instead.

How do I find the RGB values of a font color?

Select text with the color, then open Home > Font Color > More Colors > Custom and check the red, green, and blue values.

Will an RGB font color change when I switch themes?

No. Selection.Font.Color = RGB(...) applies a fixed color rather than a theme-linked color.

How can I keep the macro in my document?

Use File > Save As and choose Word Macro-Enabled Document (*.docm). To run it later, press Alt+F8 and select the macro.