Daniel
Daniel

Reputation: 1

VBA Word - BreakLink gives me an error

I'm trying to use a macro to embed linked images in a Word doc.

When I get to the line that breaks the link, I keep getting this error: Run-time error 5352 The link does not exist

This is the bit of code I'm using to break the link:

For Each objField In ActiveDocument.Fields
  If Not objField.LinkFormat Is Nothing Then
    objField.LinkFormat.BreakLink
    ActiveDocument.UndoClear
  End If
Next

Any ideas why this isn't working? I can't see why I would get this error.

Upvotes: 0

Views: 705

Answers (1)

Daniel
Daniel

Reputation: 1

I found the solution - refresh the image before trying to break the link:

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

Upvotes: 0

Related Questions