Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert a pdf document into MS word with vbscript?

Status
Not open for further replies.

rdjn13

Programmer
Jul 31, 2015
1
US
Hello,

I trying to using VBScript to populate a word document. I made a template word document (.dotx) with preset bookmarks for my VBScript to look for. I have no problem adding a string of text to the document but I run into a problem when I want to add a PDF file to the word document. Here is the code I used for adding the PDF:

Set pdf = doc.Bookmarks("pdf").Range.InlineShapes.AddOLEObject Left:=100, Top:=100, Width:=200, Height:=300, _ FileName:="C:/Users/Jeby/AppData/Local/Temp/S10/bullseye.pdf", DisplayAsIcon:=True

When I try running this script, I get an error that says "Expected end of statement" at character 74, which is after the AddOLEObject part of the script line. I've tried different variations of my code to try and troubleshoot but I keep getting an error. Can someone help me with this?

 
Hi,

Open MS Word. Turn on the macro recorder and record doing what you want to do. Stop the macro recorder and then observe the recorded code as a basis for your objectives.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Forum707

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
look at COMMA UNDERSCORE in the AddOLEObject method.

Remove the UNDERSCORE.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
If your code is over multiple lines, the underscore should come at the end of line with no trailing spaces. If it is all on one line, there should be no underscores at all
Code:
Set pdf = doc.Bookmarks("pdf").Range.InlineShapes.AddOLEObject _
     Left:=100, _
     Top:=100, _
     Width:=200, _
     Height:=300, _
     FileName:="C:/Users/Jeby/AppData/Local/Temp/S10/bullseye.pdf", _
     DisplayAsIcon:=True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top