Set font color in Excel

with AutoHotkey

by Denis Lamarre
last updated August 8, 2016
difficulty.png easy

by Denis Lamarre


The following AHK script allows you to set a font color (blue) in Excel (if Excel is the active application and you are not editing a cell). It is also a good starting point 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 ) without using the mouse. All of this will allow you to save time and focus on your work.



overlay-um-excelfontcolor.gifPrepare your overlay
Choose an unassigned key on the Enterpad for which you want to set the font color. Use an appropriate name. This example uses "FONT color BLUE".


Code installation
Copy/paste the following script in your AutoHotkey script template (Enterpad.ahk) at the chosen key location.

  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. A decimal number from 0 to 56 is allowed as a color index. The following table shows the index of some of the 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: