PDA

View Full Version : [SOLVED:] How to find the PATH and FILENAME in inserted links in word documents ??



ksor
10-22-2019, 08:14 AM
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 :thumb

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

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

:banghead:

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

What am I doing wrong here ?

ksor
10-23-2019, 07:16 AM
No one have any idea what I'm doing wrong ?

ksor
10-23-2019, 11:32 PM
MAYDAY, MAYDAY ... HELP, HELP : pray2:: pray2:: pray2:

ksor
10-27-2019, 03:39 AM
We're sinking - SOS :crying:

Paul_Hossler
10-27-2019, 07:49 AM
The linked InlineShape seems to be a 'Package'


https://social.msdn.microsoft.com/Forums/vstudio/en-US/c751c3ae-235d-4327-a26b-74fc297263b6/word-embedded-object-of-type-quotpackagequot?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/CSOfficeDocumentFileExtract-e5afce86


Possibly that could get the file name

gmaxey
10-27-2019, 08:21 AM
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

ksor
10-27-2019, 08:48 AM
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

ksor
10-27-2019, 08:52 AM
> 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 ?

gmaxey
10-27-2019, 09:08 AM
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.

ksor
10-27-2019, 09:40 AM
> 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 ?

Paul_Hossler
10-31-2019, 07:54 AM
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

25356




You won't get information from it with VBA.

This is true. Once it's embedded, it seems to lose it's identity

ksor
10-31-2019, 08:56 AM
> 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 ?

Paul_Hossler
10-31-2019, 09:40 AM
> 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

ksor
10-31-2019, 10:07 AM
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 !)

25357

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

Paul_Hossler
11-02-2019, 07:50 AM
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


25364

ksor
11-02-2019, 08:55 AM
I've decided to use Hyperlinks instead - it's too sophisticated to do anything with this "Package-object".

Thx for you time and advices !:bow: