Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •