Set font color in Excel

with AutoHotkey

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

Description

The following AutoHotkey script lets you set a font color in Excel. The script can also be easily adapted to set several other useful commands (e.g. protect/unprotect a worksheet, set a cell formula/color/border, set currency, set conditional formatting). 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).

Steps

1

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".

2

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

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

More Info

The last number (5) at line #15 sets the color of the font to blue. The following table provides an index of 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