【问题标题】:How to use "save as" command in AppleScript with MS Word如何在带有 MS Word 的 AppleScript 中使用“另存为”命令
【发布时间】:2019-08-09 05:44:18
【问题描述】:

我想使用 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 脚本 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

【问题讨论】:

    标签: ms-word applescript


    【解决方案1】:

    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
    

    【讨论】:

    • 你的代码成功了!谢谢!!我认为“另存为”命令有问题,但我的路径错误。
    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    相关资源
    最近更新 更多