Microsoft Word - Insert pdf in word doc via macro vs. insert object

Asked By U L
15-Aug-09 10:00 PM
Word version: 97-2000

Background:  I need to insert 200+ small (~40KB) pdf files into a Word doc.

Doing it manually works fine via Insert->Object->Adobe Acrobat Document.

Now I wanted to automate the process and wrote a little VB macro (see below.).

Problem: When I save the document where I inserted the file manually it's ~80KB. However, a document where I inserted the file via the macro is 1.5MB

I'm new to VB , so what am I missing?

Thank you


Sub Macro1()

Dim strFileName As String

strFileName = "D:\tmp\test.pdf"

Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.7", _
        FileName:=strFileName _
        , LinkToFile:=False, DisplayAsIcon:=False

End Sub


The only difference that i see is the Acrobat version and use a File Picker dialog box in your macro instead of hardcoding the file name  The only difference that i see is the Acrobat version and use a File Picker dialog box in your macro instead of hardcoding the file name

15-Aug-09 10:25 PM
It can be easily identified if you have only version of the reader installed, so that the manual insert and the macro insert can use the same version. 

Other than that your code is fine, but i wouldn't recommend you to hard code the file names as it does not serve the purpose.

I would suggest you to use a File Picker dialog box as shown in the below macro.

SubMacro1()
Dim FoundFile As Variant
Dim vName As Variant
With Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
  If .Show = -1 Then
       For Each FoundFile In .SelectedItems
            vName = FoundFile 'gets new filepath
       On Error GoTo Alternate
          Selection.InlineShapes.AddOLEObject FileName:=vName, LinkToFile:=False, _
          DisplayAsIcon:=False
       GoTo NextShape
      Alternate:
        Selection.InlineShapes.AddOLEObject ClassType:="Package", FileName:=vName, _
          LinkToFile:=False, DisplayAsIcon:=False
      NextShape:
   Next
 End If
End With
End Sub

How to determine which Acrobat version Word is using?  How to determine which Acrobat version Word is using?

17-Aug-09 09:32 AM
There is only one version of Acrobat reader installed. I actually upgraded to 9.1.0 to see if the previous version was the reason for the issue.

I don't know how I can tell what exactly Word is using. I did open the files in binary and both contain a (identical looking) block with AcroExch.Document.7 in the data. The big file has a lot of data preceding that block.

I got a chance to try things in Word 2007 on another machine and the docx file does not get big when using the macro insert.  However, saving it as a doc file creates a big file.  I may have to convince those involved in the project and not able to handle docx to upgrade....

I'm still curious about the reason for the file size difference.

Thanks for the file picker sample.  The hard coded file name was purely for testing.  My intention is to use some list of file names, find the files and insert them in the order of the list. Ideally the macro would read the list from a text file. Time to study....
Create New Account
help
Microsoft Word Starts Only in Safe Mode after Adobe Acrobat Instal Word Microsoft Word will only start in Safe Mode ever since Adobe Acrobat was installed. It seems related to Adobe's automatic installation of toolbar objects in both Outlook and Word. Word reports that there
converting adobe doc into word txt Word I pasted an adobe doc into word and was trying to convert it into txt in word (adobe doc just plain txt)-am i being stupid? Word Drawing Graphics Discussions Microsoft Word (1) Adobe (1) PDF (1) CleanWebText (1) DocTools (1) Document
Using Myriad Pro font with Word? Word Can I obtain Myriad Pro font to use in Word? Myriad Pro is in Adobe In Design CS2 Word Document Management Discussions Microsoft Word (1) Adobe (1) Word (1) Adobe In Design (1) Fonts (1) Myriad Pro font (1) Word Myriad
How do you switch or change pages arount in Microsoft Word? Word Is it possible to 'select and move' page 2 to page 1 and vice versa, basically move pages around like you can with Adobe? Word Page Layout Discussions Microsoft Word (1) Adobe (1) Recalculates (1) Arount (1) Vice (1) Sus (1) No, it isn't possible quite
Microsoft Word Has Stopped Working" Displayed Upon Exit Word I'm running Vista Home Premium (32-bit), and I'm having an issue with Microsoft Office 2007. Sometimes immediately after I save a document and close Word, I get the error message "Microsoft Word has stopped working, " and then, right after Microsoft Word is being restarted." Then Microsoft Word opens to a blank document. Prior to closing