如何在带有MS Word的AppleScript中使用“另存为”命令

时间:2019-08-09 05:44:18

标签: ms-word applescript

我想使用AppleScript将MS Word文档(docx)转换为PDF。

我使用脚本编辑器尝试了以下代码。 (MS Word文档已预先打开。)

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

,失败并显示错误:

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

版本

  • macOS Mojave 10.14.4
  • Microsoft Word for Mac 16.27(19071500)
  • 脚本编辑器2.11(203.1),Apple Script 2.7

使用PowerPoint

以下代码有效。它已成功将test.pdf保存在~/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 个答案:

答案 0 :(得分:0)

outpath仍然无效,并且必须是HFS路径

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