Note that there are some explanatory texts on larger screens.

plurals
  1. POSave embedded Word Doc as PDF
    primarykey
    data
    text
    <p><strong>SCENARIO</strong></p> <p>A word document is embedded in Excel 2011 file. I need to save it as a pdf.</p> <p>Had it been Excel 2010 then it wouldn't have been a problem as MS-Office in Win Pcs support OLE automation.</p> <p><strong>WHAT HAVE I TRIED?</strong></p> <p>This is the code that I tried in Excel 2010 which works.</p> <pre><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></pre> <p>Obviously I cannot use the same in MAC. Not that I didn't try this in MAC... I did :-/ (<em>Basic human nature I guess?</em>). It failed as expected. :)</p> <p>For Excel 2011, I tried this. It works but doesn't create a pdf nor does it give any error message. I tried debugging it but no joy.</p> <pre><code>'~~&gt; 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 &amp; ".pdf" oDoc.SaveAs Filename:=oDoc.FullName &amp; ".pdf", FileFormat:=wdFormatPDF oDoc.Close savechanges:=False Next oDoc oWord.Quit Set oworddoc = Nothing Set oWord = Nothing Application.ScreenUpdating = True End Sub </code></pre> <p>I believe this can also be done using AppleScript. So I tested with Applescript as well. Here I am trying to convert a word document directly to pdf. If I get this part then I can take a small detour in my code :)</p> <pre><code>Sub tester() Dim scriptToRun As String scriptToRun = "set pdfSavePath to " &amp; Chr(34) &amp; "Users:siddharth:Documents:Sid.pdf" &amp; Chr(34) &amp; Chr(13) scriptToRun = scriptToRun &amp; "set theDocFile to choose file with prompt " &amp; Chr(34) &amp; "Please select a Word document file:" &amp; Chr(34) &amp; Chr(13) scriptToRun = scriptToRun &amp; "tell application " &amp; Chr(34) &amp; "Microsoft Word" &amp; Chr(34) &amp; Chr(13) scriptToRun = scriptToRun &amp; "open theDocFile" &amp; Chr(13) scriptToRun = scriptToRun &amp; "set theActiveDoc to the active document" &amp; Chr(13) scriptToRun = scriptToRun &amp; "save as theActiveDoc file format format PDF file name pdfSavePath" &amp; Chr(13) scriptToRun = scriptToRun &amp; "end tell" &amp; Chr(13) Debug.Print scriptToRun 'Result = MacScript(scriptToRun) 'MsgBox Result End Sub </code></pre> <p>However I get the runtime error on <code>MacScript(scriptToRun)</code> so I am sure that my Applescript is failing.</p> <p><strong>SNAPSHOT</strong></p> <p><img src="https://i.stack.imgur.com/iGl97.png" alt="enter image description here"></p> <p>Applescript Error</p> <p><img src="https://i.stack.imgur.com/4DkaA.jpg" alt="enter image description here"></p> <p><strong>QUESTION</strong></p> <p>How can I save the embedded word doc in Excel 2011? I am open to VBA and Applescript.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload