Save embedded Word Doc as PDF

强颜欢笑 提交于 2019-11-30 19:27:47

Well, I will be damned!

Thanks Pradeep for your suggestion. Seems like the application that you were referring to is obsolete with new MAC versions. So I searched the MAC Store and found another application called SMILE.

I tested the original script in in SMILE. There was nothing wrong with it and it worked perfectly!!!

set pdfSavePath to "Users:siddharth:Documents:Sid.pdf"
set theDocFile to choose file with prompt "Please select a Word document file:"
tell application "Microsoft Word"
    open theDocFile
    set theActiveDoc to the active document
    save as theActiveDoc file format format PDF file name pdfSavePath
end tell

So I tried the code which I was testing earlier and to my surprise, it worked this time without me making any change to the original code!!! So I am stumped on what could be the problem... Did Smile install something which made the script work in Excel? Guess I will never find out.

Option Explicit

Sub tester()
    Dim scriptToRun As String

    scriptToRun = "set pdfSavePath to  " & Chr(34) & "Users:siddharth:Documents:Sid.pdf" & Chr(34) & Chr(13)
    scriptToRun = scriptToRun & "set theDocFile to choose file with prompt " & Chr(34) & "Please select a Word document file:" & Chr(34) & Chr(13)
    scriptToRun = scriptToRun & "tell application " & Chr(34) & "Microsoft Word" & Chr(34) & Chr(13)
    scriptToRun = scriptToRun & "open theDocFile" & Chr(13)
    scriptToRun = scriptToRun & "set theActiveDoc to the active document" & Chr(13)
    scriptToRun = scriptToRun & "save as theActiveDoc file format format PDF file name pdfSavePath" & Chr(13)
    scriptToRun = scriptToRun & "end tell" & Chr(13)

    Debug.Print scriptToRun
    Result = MacScript(scriptToRun)
    MsgBox Result
End Sub

SMILE SNAPSHOT

EDIT: FOUND THE ERROR

On closer inspection, I found that my original script had an extra line. I was setting the PDF path twice. Can be seen in the snapshot.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!