Set font size in MS Word

with AutoHotkey

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


With AutoHotkey you can easily set properties in Microsoft Word (e.g. font size, font name, font style, font color, line spacing). The following script is designed to set font size. By adapting this script, you can set any property you want in Word using AutoHotkey.



overlay-um-wordfontsize.gifPrepare your overlay
Choose an unassigned key on the Enterpad for your font size function. Name it something appropriate, like "Font size 24".


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.

  IfWinNotActive, ahk_class OpusApp
    MsgBox % "MS Word is not active. No action will be performed."
    oWord := ComObjActive("Word.Application")
    MsgBox % "Unable to execute the shortcut." 
  oWord.Selection.Font.Size := 24
  oWord :=

More Info

You can replace line #14 in the script above with any of the following commands to set properties other than font size.

Set font name to Arial Black:

oWord.Selection.Font.Name  := "Arial Black"

Set italic font style:

oWord.Selection.Font.Italic := 1

Set bold font style:

oWord.Selection.Font.Bold := 1

Unset bold font style:

oWord.Selection.Font.Bold := 0

Set font color to red:

oWord.Selection.Font.Color := 0xFF0000

Set line spacing to 10.5:

oWord.Selection.ParagraphFormat.LineSpacing := 10.5

Execute a custom MS Word macro with the name Macro1:

  MsgBox % "MS Word macro doesn't exist!"

If you want to set other properties in Word but don't know how, you can use the Word macro recorder. Activate the recorder, set the property you want, and then check the resulting macro. This will give you a clue on how to do it with AutoHotkey.