0
votes

I want to convert MS Word document (docx) to PDF with AppleScript.

I tried the code below with Script Editor. (MS Word document is opened beforehand.)

tell application "Microsoft Word"
    activate
    set outpath to "Documents/test.pdf"
    set activeDoc to active document
    save as activeDoc file name outpath file format format PDF
end tell

and failed with the error:

The active document doesn't understand "save as" message. 
number -1708 from active document

Versions

  • macOS Mojave 10.14.4
  • Microsoft Word for Mac 16.27 (19071500)
  • Script Editor 2.11 (203.1), Apple Script 2.7

With PowerPoint

The code below worked. It successfully saved test.pdf under ~/Library/Containers/com.microsoft.Powerpoint/Data/Documents.

set outpath to "Documents/test.pdf"

tell application "Microsoft PowerPoint"
    activate
    save active presentation in outpath as save as PDF
end tell
1

1 Answers

0
votes

outpath is invalid anyway and it must be an HFS path

set outpath to (path to documents folder as text) & "test.pdf"

tell application "Microsoft Word"
    activate
    set activeDoc to active document
    save as activeDoc file name outpath file format format PDF
end tell