Consulting

Results 1 to 16 of 16

Thread: How to find the PATH and FILENAME in inserted links in word documents ??

  1. #1
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location

    How to find the PATH and FILENAME in inserted links in word documents ??

    I a mainfolder I have 1000's of word documents in a subfolder and 100's of MP4-video files in another subfolder in the same mainfolder.

    I have to test to see if all inserted "link" (with a file name in it) in each word document is found as a file among the video files in the subfolder abowe.

    Just to get started I did this:

    Create a new empty word document,

    click INSERT/OBJECT
    choose TAB "Create from file"
    check both checkboxes
    choose a MP4 video file
    click OK

    (My translations because I have WORD in a danish version !)

    Then save the document and go to the immidiate window and do this typing:

    ? ActiveDocument.InlineShapes.Count
    1

    ? ActiveDocument.InlineShapes.Item(1).Type=wdInlineShapeEmbeddedOLEObject
    True

    then I try this:
    ? ActiveDocument.InlineShapes.Item(1).LinkFormat.SourceFullName



    but it gives me errormessage. Runtime error 91 - Object variable not set

    What am I doing wrong here ?

  2. #2
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    No one have any idea what I'm doing wrong ?

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    MAYDAY, MAYDAY ... HELP, HELP

  4. #4
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    We're sinking - SOS

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    The linked InlineShape seems to be a 'Package'


    https://social.msdn.microsoft.com/Fo...uot?forum=vsto


    The "Package" is a legacy of the OLE 1.0 days. Ole 1.0 had a tool called the Packager that would provide an Ole object wrapper around an arbitrary file to allow it to be embedded in a client. In Ole 2.0, they took that concept and exposed it in such a way that clients could create packages via the Insert Object dialog without needing the tool.
    Lots more technical info



    Extracting the embedded bin file from the docx, and examining it in hex I could see the file name, but the only way to extract it seems to be ...

    https://code.msdn.microsoft.com/CSOf...tract-e5afce86


    Possibly that could get the file name
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    You really aren't doing anything wrong that I can tell. The issue seems to be that despite what it looks like you are doing, what is actually happening is the object you think you are inserting and linking to an external file is actually "Embed" in the Word files. If you toggle your field codes, you will see the code it "Embedded package" information about that package is stored in an oleObject.bin file in the OpenOfficeXMLFileFormat package.

    Once a file is embedded, you are not able (with VBA at least) to determine the source path.

    You could insert a shape and create a hyperlink to your external file and return the hyperlink address:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    MsgBox ActiveDocument.Shapes(1).Hyperlink.Address
    lbl_Exit:
    Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    Quote Originally Posted by gmaxey View Post
    You really aren't doing anything wrong that I can tell. The issue seems to be that despite what it looks like you are doing, what is actually happening is the object you think you are inserting and linking to an external file is actually "Embed" in the Word files. If you toggle your field codes, you will see the code it "Embedded package" information about that package is stored in an oleObject.bin file in the OpenOfficeXMLFileFormat package.

    Once a file is embedded, you are not able (with VBA at least) to determine the source path.

    You could insert a shape and create a hyperlink to your external file and return the hyperlink address:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    MsgBox ActiveDocument.Shapes(1).Hyperlink.Address
    lbl_Exit:
    Exit Sub
    End Sub

    I don't think you're right on that ... the size of the word document should then grow with something like the size of the MP4-file and it DON'T

  8. #8
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    > Paul_Hossler

    THX big time - I'll study these links !

    BTW: Word CAN show the PATH and FILENAME in a dialogbox ... then we should be able too - if you know how - right ?

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    ksor,

    Think what you want, but as you have already proved to yourself the object you insert is an embedded object:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    MsgBox ActiveDocument.InlineShapes(1).Type
    lbl_Exit:
    Exit Sub
    End Sub

    That returns 1 or wdInlineShapeEmbeddedOLEObject. A linked object returns 2 or wdInlineShapeLinkedOLEObject.

    I didn't say that the the mp4.file was embedded, I said the object is embedded. The resulting oleObject.bin file was very small. You won't get information from it with VBA.
    Greg

    Visit my website: http://gregmaxey.com

  10. #10
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    > gmaxey

    As I said to another user - Word can present PATH and FILENAME in a dialog for the user - why shouldn't we too by VBA ?

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by gmaxey View Post
    I didn't say that the the mp4.file was embedded, I said the object is embedded. The resulting oleObject.bin file was very small.
    I'm not sure that that is always correct.

    I created Before.docx, saved it (33,731 bytes), and then Inserted Object (not linked) a 46MB mp4 file (47,871,296 bytes), and then saved that as After.docx (47,461,270 bytes).

    Breaking into the After.Docx as a zip file and looking at oleObject1.bin (48,253,952 bytes), it seems approx the same size as the mp4 file. I'm guessing that there's a OLE package wrapper around the embedded object, and that makes it a little larger

    Capture.JPG


    Quote Originally Posted by gmaxey View Post
    You won't get information from it with VBA.
    This is true. Once it's embedded, it seems to lose it's identity
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  12. #12
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    > Paul Hossler

    You gave the link to a very sopfisticated solution ... and it's WAY TOO much to do for solving my problem, but ...

    I wonder how Word can show it for the user in a dialog ?

  13. #13
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by ksor View Post
    > Paul Hossler

    You gave the link to a very sophisticated solution ... and it's WAY TOO much to do for solving my problem, but ...

    I wonder how Word can show it for the user in a dialog ?

    1. For me also

    2. I think the information is gone once it's embedded
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  14. #14
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    Quote Originally Posted by Paul_Hossler View Post
    1. For me also

    2. I think the information is gone once it's embedded
    No, you can find it in the menu: (I have a danish version, so bare with me ...)

    When you open the document with the embedded object as a icon:

    Right click on the icon
    choose Package-shell-object-object (a very strange menu item I think !)
    choose Rename package

    and you get this dialog showing the PATH and FILENAME: (in the danish version !)

    test.jpg

    So the embedded object MUST have these infos stored somewhere - right ?

    You can even rename the FILE on the disk without affecting the embedded object

  15. #15
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    True, but

    1. I don't think the properties are exposed to VBA so you really can't get to them

    2. It appears that a temporary copy is embedded. so the 'real' file name is not there


    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  16. #16
    VBAX Regular
    Joined
    Jan 2018
    Posts
    52
    Location
    I've decided to use Hyperlinks instead - it's too sophisticated to do anything with this "Package-object".

    Thx for you time and advices !

Posting Permissions

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