Austin R
Austin R

Reputation: 795

How can I embed a PDF in a Word Doc, and access that PDF with VBA?

I have a word doc with some ActiveX buttons on it. When one of these buttons is pressed, a UserForm pops up with a corresponding PDF displayed, like so:

enter image description here This is exactly the behavior I want. However, the problem is that for this to work, the user of the word doc needs to have each of the PDFs saved on their machine as well. Here's the code for one of the buttons:

Private Sub AC1Button_Click()

    DisplayForm.AcroPDF1.LoadFile ("C:\Users\arose\Desktop\Security Control Doc\Sub PDFs\AC1.pdf")
    DisplayForm.Show

End Sub

As you can see, the path is hardcoded in. I need to be able to distribute this word doc without needing to distribute a bunch of PDFs along with it, so is there any way to embed PDFs in a word document in such a way that they're accessible by VBA?

I've discovered here that it's reasonably easy to embed a PDF in any office doc. And I've tried that:

enter image description here

But I can't figure out how to access that PDF object in my VBA code, in order to display it on the UserForm.

Any insight is appreciated, thanks!

Upvotes: 1

Views: 2812

Answers (1)

SeanC
SeanC

Reputation: 15923

Embed the files (and display as icon to stop them taking over your document)

To activate the first OLE object in your document,

ThisDocument.InlineShapes(1).OLEFormat.Activate

is the command.

Upvotes: 2

Related Questions