Open multiple files in MS Word and change font type of all text to Calibri

Working with MS Word is excellent when you have AutoHotkey & COM!

Someone on the Facebook AutoHotkey group gave the following requirements

  1. Open file one
  2. open document Word
  3. CTRL+A
  4. change font to Calibri
  5. save file in another file

Here is the code wrote to open multiple files in MS Word and change the font type of all text.  COM Rocks!

Wd:=ComObjCreate("Word.Application") ;this would activate an open one
WD.Visible:=0 ;This is fun to watch, but it will be much, much faster if you set this to zero and have it running w/o being visible

;********************Get list of files***********************************
FileSelectFile,Files,m,%A_ScriptDir%,,Text Documents (*.docx; *.doc)
;*********Use For loop over Var going line by line*********************
MsgBox % Files
for i, File in Loopobj:=StrSplit(Files,"`n","`r`n") { ;Parse Var on each new line
    If (I=1){
      Path:=File "\"
    Menu , tray, tip, % round((i-1)/(Loopobj.maxindex()-1)*100) "% done. " i-1 " of " Loopobj.maxindex()-1 
    WD.Documents.Open(Path File, 0, 1, 0)
    WD.Selection.WholeStory ;Select all text
    WD.Selection.font.Name:="Calibri" ;Change the selected text to the font you want
    newFile:=Path File "_Calibri.docx" ;Add _Calibri to the name (note this will overwrite other files)
WD.Quit() ;Make sure you quit Word when it is done
MsgBox Done!

Here’s a walk-through video open multiple files in MS Word

Comments are closed.