3
1
I have a Word document with pictures that are linked. I want to embed them to the word document, but I do not want to do it manually.
Manually going to: File --> edit links to files --> selecting and hitting "break link" does exactly what I want to do.
I found some VBA code for breaking links to fields, but that does not help to break the links to my pictures. Here is the code that I tried:
For Each objField In ActiveDocument.Fields
If Not objField.LinkFormat Is Nothing Then
objField.LinkFormat.Update
objField.LinkFormat.BreakLink
ActiveDocument.UndoClear
End If
Next
When I hit Alt + F9 in my document to display fields nothing happends to my pictures, but other fields (links etc) is expanded/displayed. I therefore assume that these picture links are something else than "fields".
How can I break these picture links in VBA?
Edit Note The word document is basically a html file. That is what you get by opening a .html file in Word.
What type of field does your images appear as before and after that macro is run? – Adam – 2013-09-13T12:29:58.960
@Adam: As far as I can see, no type of filed. I tried the Alt + F9 to see the field type, but nothing happens to my pictures – exalt – 2013-09-15T11:16:55.853
What does the context menu look like when you right click on the image? Are there any references to packages or buttons such as "Activate contents" or "Convert"? Otherwise, you might just have a regular image embedded in your document with no link to start with :) – Adam – 2013-09-16T05:00:36.023
@Adam it looks "normal", unfortunatly I cant post pictures yet (due to repudiation), but there is no "activate contents" "convert" etc. Although I know the image is not embedded. The size is 10kb, after breaking 1 link is is typically 50kb. Also, moving the document results in the images not being displayed as the links are relative. – exalt – 2013-09-16T06:48:28.303
Sounds strange. Can you try running the following code to determine if they are fields at all? (remove all other content temporarily).
– Adam – 2013-09-17T12:15:35.613For Each Field In ActiveDocument.Fields MsgBox (Field.Type) Next Field
Resolved field types by looking up WdFieldType Enumeration@Adam Thanks for the tip, as a result I was able to fix it! The code you provided did not result in any output at first try. Then I saved the document as .doc and tried again, this time getting an id. I then tried to run the breakLinks macro and it worked. The reason (I guess) is that the Word document was in fact a html-file. So without saving it first Word hadn't added the necessary metadata to identify the fields. – exalt – 2013-09-18T12:33:49.013
Well done. You can post this as the answer to your own question and accept it. – Adam – 2013-09-18T12:59:32.340