Break link to picture programatically in MS Word 2010

exalt

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.

exalt

As the word document was in fact a html document opened in Word it did not include word specific markup to identify the fields. As a result the GUI functionality worked, but not the vba solution as detailed in the question. The solution was to first save the word document with a new name (thus generating word markup), and then run the breakLinks macro.

Macro for saving the document:

Sub saveAsDoc()
    Dim newName As String
    newName = ActiveDocument.Path & "\" & "fix_" & ActiveDocument.Name
    ActiveDocument.SaveAs2 FileName:=newName, FileFormat:=wdFormatDocument
End Sub

Macro for breaking links:

Sub breakLinks()
For Each objField In ActiveDocument.Fields
  If Not objField.LinkFormat Is Nothing Then
    objField.LinkFormat.Update
    objField.LinkFormat.BreakLink
    ActiveDocument.UndoClear
  End If
Next
End Sub

Main macro that should be executed from a extrenal script. The displayAlerts is to make sure there are no pop-us.

Sub theTrick()
    Application.DisplayAlerts = False
    Call saveAsDoc
    Call breakLinks
    ActiveDocument.save
    Application.DisplayAlerts = True
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inserting A Line Break (Not A Paragraph Break) Programatically To A Word Document

From Dev

Break link with external document MS Word

From Dev

How to force MS Word 2010 to split words anywhere

From Dev

Creating MS Word 2010 Relative Links?

From Dev

How to identify number of single section for printing in MS Word 2010?

From Dev

How programatically set text styling in ms word?

From Dev

Problems Accessing MS Word 2010 with Python

From Dev

MS Word 2010/2013 Cannot select text after typing

From Dev

MS Office files opening with 2010 Word/Excel, not 2016 versions

From Dev

MS Office 2010 Word change character encoding

From Dev

MS Word 2010 - how to create simple bibliography to reference it

From Dev

Custom Date Format in MS Word 2010

From Dev

MS WORD. How to create link to a picture within the same document?

From Dev

Text variables in MS Word 2010?

From Dev

Hyperlinks pasted in MS Word 2010 inactive

From Dev

How to fix the position of a picture on a fixed page, in MS Word 2013?

From Dev

MS Word 2010 - keyboard shortcut for replace that uses selected text

From Dev

MS Word 2010 weird page sizes while editing

From Dev

How to set position of picture in word 2010

From Dev

Ambiguous procedure error MS Word 2010 VBA

From Dev

How can I set the dimensions of a picture/image in terms of the page/margin/column dimensions in MS Word 2010?

From Dev

Word Count in MS Excel 2010

From Dev

Table of content in MS Word 2010

From Dev

Ms word Shortcut Key combo for section break

From Dev

How to put a line break in an equation in MS Word 2007 or newer

From Dev

MS Word: remove "page break before" for one instance of heading?

From Dev

Can't delete paragraph break in ms-word

From Dev

how to clear a picture content control with macro in ms word

From Dev

Embed a text file as an object in Ms Word 2010

Related Related

  1. 1

    Inserting A Line Break (Not A Paragraph Break) Programatically To A Word Document

  2. 2

    Break link with external document MS Word

  3. 3

    How to force MS Word 2010 to split words anywhere

  4. 4

    Creating MS Word 2010 Relative Links?

  5. 5

    How to identify number of single section for printing in MS Word 2010?

  6. 6

    How programatically set text styling in ms word?

  7. 7

    Problems Accessing MS Word 2010 with Python

  8. 8

    MS Word 2010/2013 Cannot select text after typing

  9. 9

    MS Office files opening with 2010 Word/Excel, not 2016 versions

  10. 10

    MS Office 2010 Word change character encoding

  11. 11

    MS Word 2010 - how to create simple bibliography to reference it

  12. 12

    Custom Date Format in MS Word 2010

  13. 13

    MS WORD. How to create link to a picture within the same document?

  14. 14

    Text variables in MS Word 2010?

  15. 15

    Hyperlinks pasted in MS Word 2010 inactive

  16. 16

    How to fix the position of a picture on a fixed page, in MS Word 2013?

  17. 17

    MS Word 2010 - keyboard shortcut for replace that uses selected text

  18. 18

    MS Word 2010 weird page sizes while editing

  19. 19

    How to set position of picture in word 2010

  20. 20

    Ambiguous procedure error MS Word 2010 VBA

  21. 21

    How can I set the dimensions of a picture/image in terms of the page/margin/column dimensions in MS Word 2010?

  22. 22

    Word Count in MS Excel 2010

  23. 23

    Table of content in MS Word 2010

  24. 24

    Ms word Shortcut Key combo for section break

  25. 25

    How to put a line break in an equation in MS Word 2007 or newer

  26. 26

    MS Word: remove "page break before" for one instance of heading?

  27. 27

    Can't delete paragraph break in ms-word

  28. 28

    how to clear a picture content control with macro in ms word

  29. 29

    Embed a text file as an object in Ms Word 2010

HotTag

Archive