• Insert a document object with relative path (Word 2000 VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Insert a document object with relative path (Word 2000 VBA)

    Author
    Topic
    #361622

    I am trying to insert a MS Word Document object into another document through VBA. I can do this all day long if I give an absolute path.

    However, if I try to use a relative path, I get the message:

    “Word cannot obtain the data for the [document name] link.”

    The code I am using to insert is:

    Selection.InlineShapes.AddOLEObject ClassType:=”Word.Document.8″, FileName _
    :=”Object1.doc”, LinkToFile:=False, DisplayAsIcon _
    :=False

    F.Y.I. I have tested inserting other documents with the same results, so I don’t think it is the document I am inserting that is causing the problem. Also, I tried replacing the file name here with a text file, and Word did allow that to be inserted from a relative path (although it kept inserting it as an icon, but it least it found it).

    Thanks for your help!!
    Troy

    Viewing 0 reply threads
    Author
    Replies
    • #547896

      I wanted to reply for the information of others, since I found this answer on another newsgroup.

      From “Cindy Meister -WordMVP-” <CindyMeister@swissonline.ch

      It's quite understandable why a method that inserts an object
      wants to have a full path. Is your issue picking up the file
      from a relative location? Then use ActiveDocument.Path & "" &
      "Filename"

      So the new code that works for me is:

      Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
      :=ActiveDocument.Path & "" & "Object.doc", LinkToFile:=False, DisplayAsIcon _
      :=False

      Enjoy!!
      Troy

    Viewing 0 reply threads
    Reply To: Insert a document object with relative path (Word 2000 VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: