Link to home
Start Free TrialLog in
Avatar of Bryce Bassett
Bryce BassettFlag for United States of America

asked on

Possible to embed VBA code in a Word document to cause printing of embedded PDFs when document is printed?

Working on a proposal-writing tool in MS Word.  My VBA toolbar assists the user in document creation.  One feature is to embed PDF product data sheets into the Word document as needed.  I've done a lot of research and experimenting and can't find a foolproof way to embed the PDF object in a way that will display each PDF page on a separate Word page.  Word 2016 does a pretty decent job of importing PDFs into Word, but there are reflow issues so it's spotty.  Best I've come up with is tell the document recipient they need to double click on each embedded PDF (icon or first page preview) to open and print it separately from the Word print command.  

Anybody seen or come up with a way to save the customer from having to do that?  Ideally, VBA could programmatically open each embedded PDF object and print it at the same time the customer prints the Word document?  Or we could display a dialog that prompts "this document has embedded PDFs.  Click here to open and print each one" But is there a method to open embedded PDF objects and send them to the printer?

Any ideas would be appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Daniel Pineault
Daniel Pineault

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bryce Bassett

ASKER

Thanks, Daniel

I'm iterating the inlineshapes to find my embedded PDFs (assumes that all wdInlineShapeEmbeddedOLEObject's are PDFs, which I can control).  Found another post suggesting a method to open these.  So the following code locates and opens my embedded PDFs, but the user still has to manually switch over to Acrobat reader to print them.  

    If ActiveDocument.InlineShapes.Count > 0 Then
      For Each myshape In ActiveDocument.InlineShapes
        If myshape.Type = wdInlineShapeEmbeddedOLEObject Then
            Set myformat = myshape.OLEFormat
            myformat.Open
        End If
      Next myshape
    End If

Open in new window

Is there any way my VBA code can tell Acrobat to print the objects it has opened?  The trick is I will not know what application on the document recipient's machine is opening the PDF (Acrobat reader, Full Acrobat, etc.) nor will I know its location.

Or is there a tricky workaround, like, locate my embedded PDFs, save them out to temporary files, print them from VBA, kill the temporary files, etc.

Any ideas?
I ended up embedding the first-sheet preview and having the user click to expand that.  Best way to retain the original PDF fidelity.  Thanks,