Ms word 使用Applescript在Word中另存为活动文档的正确语法是什么?

Ms word 使用Applescript在Word中另存为活动文档的正确语法是什么?,ms-word,applescript,ms-office,Ms Word,Applescript,Ms Office,我快发疯了。我尝试过无数种“另存为活动文档文件格式PDF”的排列/变体,但似乎都不起作用。所有这些都有AppleScript错误 谁能告诉我: 使用Word将活动文档保存为AppleScript中的PDF文件的确切语法是什么 在Office for Mac脚本中似乎没有任何一致性,因为我在Excel和PowerPoint中使用了它,即使在那里,语法也不同: 胜过 幻灯片 save active presentation in 'MyFile.pdf' as save as PDF Word的正

我快发疯了。我尝试过无数种“另存为活动文档文件格式PDF”的排列/变体,但似乎都不起作用。所有这些都有AppleScript错误

谁能告诉我:

使用Word将活动文档保存为AppleScript中的PDF文件的确切语法是什么

在Office for Mac脚本中似乎没有任何一致性,因为我在Excel和PowerPoint中使用了它,即使在那里,语法也不同:

胜过

幻灯片

save active presentation in 'MyFile.pdf' as save as PDF
Word的正确语法是什么


谢谢

看来我终于找到了:

set myDoc to "/Users/X/Desktop/test.docx"
set pdfSavePath to "Users:X:Desktop:test.pdf"

tell application "Microsoft Word"
        activate
        open myDoc
        set theActiveDoc to the active document
        save as theActiveDoc file format format PDF file name pdfSavePath
    end tell

我不是苹果书专家。我用斜线代替:作为路径分隔符。With:it work

Joris Mans的脚本相当不错,但有一个缺陷。它不能确保Word已准备好活动文档(
将ActivateDoc设置为活动文档
可能返回缺少的值)

我还改进了脚本,使用Finder选择作为输入,将PDF放在与word文件相同的位置。我没有测试文件类型,但是word会对此抱怨

tell application "Finder"
    set input to selection
end tell

tell application id "com.microsoft.Word"
    activate
    repeat with aFile in input
        open aFile
        set theOutputPath to ((aFile as text) & ".pdf")
        repeat while not (active document is not missing value)
            delay 0.5
        end repeat
        set activeDoc to active document
        save as activeDoc file name theOutputPath file format format PDF
        close active document saving no
    end repeat
end tell
tell application "Finder"
    set input to selection
end tell

tell application id "com.microsoft.Word"
    activate
    repeat with aFile in input
        open aFile
        set theOutputPath to ((aFile as text) & ".pdf")
        repeat while not (active document is not missing value)
            delay 0.5
        end repeat
        set activeDoc to active document
        save as activeDoc file name theOutputPath file format format PDF
        close active document saving no
    end repeat
end tell