Set font color in Excel

with AutoHotkey

by Denis Lamarre
last updated January 31, 2019
difficulty.png easy

by Denis Lamarre


The following AutoHotkey script lets you set a font color in Excel, in this case blue. The script can also be easily adapted to set several other useful commands (like protect/unprotect a worksheet, set a cell formula/color/border, set currency, set conditional formatting, and so on). The script will set the font color if the Excel worksheet is the active window and is not busy (e.g. editing, selecting a command).



overlay-um-excelfontcolor.gifPrepare your overlay
Choose an unassigned key on the Enterpad for your font color function. Name it something appropriate like "Font color BLUE".


Code installation
Copy and paste the following script in the AutoHotkey script template file "Enterpad.ahk" at the location of the key you wish to assign.

  IfWinNotActive, ahk_class XLMAIN
    MsgBox % "Excel is not active. No action will be performed."
    epExcel := ComObjActive("Excel.Application")
    MsgBox % "Unable to execute the shortcut."
    epExcel.Selection.Font.ColorIndex := 5
    MsgBox % "Unable to set the color."
  epExcel :=

More Info

The last number (5) at line 15 sets the color of the font to blue. The following table provides an index for some popular colors:

Auto 0
Black 1
White 2
Red 3
Bright Green 4
Blue 5
Yellow 6
Pink 7
Turquoise 8
Dark Red 9
Green 10
Dark Blue 11
Dark Yellow 12
Violet 13
Teal 14
Grey 25 15
Grey 50 16

Some setups allow to run more than one Excel process at the same time. The script above is not intended to work with these kinds of setups. The following post (on the AutoHotkey forum) explains a more efficient way to run a macro while multiple Excel processes are active: