Cedeq Community Forum
Keyboard Shortcut - Set Font Color in Excel - Printable Version

+- Cedeq Community Forum (https://forum.cedeq.com)
+-- Forum: General (https://forum.cedeq.com/forumdisplay.php?fid=1)
+--- Forum: Keyboard shortcuts with AutoHotkey code (https://forum.cedeq.com/forumdisplay.php?fid=4)
+--- Thread: Keyboard Shortcut - Set Font Color in Excel (/showthread.php?tid=15)

Keyboard Shortcut - Set Font Color in Excel - denilama - 02-27-2018

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 (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).

Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
if WinActive("ahk_class XLMAIN")
  ControlGet, hwnd, hwnd, , Excel71, A
  if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hwnd, "UInt", 0xFFFFFFF0, "Ptr", -VarSetCapacity(IID,16)+NumPut(0x46000000000000C0, NumPut(132096, IID, "Int64"), "Int64"), "Ptr*", pacc) = 0
    ExcelApp := ComObject(9, pacc, 1).Application
  ExcelApp.Selection.Font.ColorIndex := 3
  MsgBox 0x40040, ShortKeeper, There is no Excel worksheet window active.

The last number (3) at line #7 sets the color of the font to red. A decimal number from 0 to 56 allows for different color options. The following list includes some common color choices:
  • 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

This script is optimized to be used with ShortKeeper. As such, there is no exception handling, no “Return” at the end, and variable(s) don’t need to be cleared. ShortKeeper does all of this automatically. Just copy/paste the code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.