none
copy Embedded pdf document from Excel to Word RRS feed

  • Question

  • Hi, I have a list of PDF file paths in Excel and I need to create a Word document that contains these as embedded files. I was able to write code in VBA that uses the file paths to create the embedded objects in the Excel file. However if I copy this to a Word document, it changes into an image and the file can no longer be opened by double clicking on the icon in Word.
    Wednesday, February 7, 2018 4:25 PM

All replies

  • Hello Juret5,

    Since you have the PDF file path, I would suggest you create embedded files in the Word Document directly instead of creating in Excel file and then copy to Word Document.

    Here is the code example.

    'Add reference to Microsoft Word X Object Model
    Sub TEST()
    Dim wdApp As Word.Application
    Dim newDoc As Word.Document
    Set wdApp = CreateObject("Word.Application")
    Set newDoc = wdApp.Documents.Add
    
    Dim ws As Worksheet
    Set ws = ActiveSheet
    'i put 6 path in cells A1:A6 for testing
    'adjust it to get pdf path for your need
    For i = 1 To 6
    pdfPath = ws.Cells(i, 1).Value
    newDoc.Content.InlineShapes.AddOLEObject ClassType:="Package", Filename:=pdfPath, LinkToFile:=False, _
            DisplayAsIcon:=False
    Next i
    wdApp.Visible = True
    End Sub
    

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 8, 2018 2:58 AM