Zapisz osadzony Word Doc w formacie PDF

SCENARIUSZ

Dokument programu Word jest osadzony w pliku Excel 2011. Muszę go zapisać w formacie pdf.

Gdyby to był Excel 2010, nie byłoby problemu, ponieważ MS-Office w Win Pcs obsługuje automatyzację OLE.

CO MIAŁEM PRÓBĘ?

To jest kod, który wypróbowałem w Excelu 2010, który działa.

<code>Option Explicit

Sub Sample()
    Application.ScreenUpdating = False

    Dim shp As Shape
    Dim objWord As Object
    Dim objOLE As OLEObject

    Set shp = Sheets("Sheet1").Shapes("Object 1")

    shp.OLEFormat.Activate

    Set objOLE = shp.OLEFormat.Object

    Set objWord = objOLE.Object

    objWord.ExportAsFixedFormat OutputFileName:= _
            "C:\Users\Siddharth Rout\Desktop\Sid.pdf", ExportFormat:= _
            17, OpenAfterExport:=True, OptimizeFor:= _
            0, Range:=0, From:=1, To:=1, _
            Item:=0, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=0, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False

    objWord.Application.Quit

    Set objWord = Nothing
    Set shp = Nothing
    Set objOLE = Nothing

    Application.ScreenUpdating = True
End Sub
</code>

Oczywiście nie mogę używać tego samego w MAC. Nie, że nie próbowałem tego w MAC ... Zrobiłem: - / (Myślę, że podstawowa natura ludzka?). Nie udało się zgodnie z oczekiwaniami. :)

W przypadku programu Excel 2011 próbowałem tego. Działa, ale nie tworzy pliku PDF ani nie wyświetla żadnego komunikatu o błędzie. Próbowałem to debugować, ale bez radości.

<code>'~~> Reference set to MS Word Object Library
Option Explicit

Sub Sample()
    Dim oWord As Word.Application, oDoc As Word.Document

    Application.ScreenUpdating = False

    Sheets("Sheet1").Shapes.Range(Array("Object 1")).Select

    Selection.Verb Verb:=xlPrimary

    Set oWord = GetObject(, "word.application")

    For Each oDoc In oWord.Documents
        Debug.Print oDoc.FullName & ".pdf"

        oDoc.SaveAs Filename:=oDoc.FullName & ".pdf", FileFormat:=wdFormatPDF
        oDoc.Close savechanges:=False
    Next oDoc

    oWord.Quit

    Set oworddoc = Nothing

    Set oWord = Nothing
    Application.ScreenUpdating = True
End Sub
</code>

Uważam, że można to również zrobić za pomocą AppleScript. Przetestowałem również z Applescript. Tutaj próbuję przekonwertować dokument Word bezpośrednio na pdf. Jeśli dostanę tę część, mogę zrobić mały objazd w moim kodzie :)

<code>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
</code>

Jednak pojawia się błąd wykonaniaMacScript(scriptToRun) więc jestem pewien, że mój Applescript zawodzi.

MIGAWKA

Błąd Applescript

PYTANIE

Jak mogę zapisać osadzony dokument programu Word w programie Excel 2011? Jestem otwarty na VBA i Applescript.

questionAnswers(1)

yourAnswerToTheQuestion