Set font size in MS Word

with AutoHotkey

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

by Denis Lamarre

Description

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

Steps

1

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

2

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.

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

More Info

You can replace line 14 in the above script with any of the following commands to set something other than the 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:

try
  oWord.Run("Macro1")
catch
  MsgBox % "MS Word macro doesn't exist!"

If you want to set some other parameter in MS Word but don't know how, do it with the Word macro recorder activated and check the resulting macro. This will give you a clue on how to do it with AutoHotkey.