.BreakLink does one only

E

Evan

The following code breaks the link to the first of three
shapes
and then complains, "Object variable or With block
variable not set":

BrkLnk = True
....
For Each iShape In ActiveDocument.InlineShapes
With iShape
...
If BrkLnk Then .LinkFormat.BreakLink
End With
...
Next iShape

Any ideas?
 
P

Peter Hewett

Hi Evan

When inserting an inline shape into your document/template you have two
options. You can either link to the original picture or not. Doing this:
Insert>Picture>From File>Insert, generates this code:

Selection.InlineShapes.AddPicture FileName:="C:\bath.jpg", _
LinkToFile:= False, SaveWithDocument:=True

However, doing this: Insert>Picture>From File>Link to file, generates this
code:

Selection.InlineShapes.AddPicture FileName:="C:\bath.jpg", _
LinkToFile:= True, SaveWithDocument:=False

Both of these statements generate InlineShape objects. However, when you
set LinkToFile to True, Word inserts an INCLUDEPICTURE field. You can only
unlink InlineShapes that have a corresponding field.

The problem with your code is that the shape you are processing at the time
your code bombs has no LinkFormat object (it's actually Nothing). In other
words the InlineShapes not linked it's embedded.

So try the following:

Public Sub UnlinkInlineShapes()
Dim IShape As Word.InlineShape

For Each IShape In ActiveDocument.InlineShapes
With IShape
If Not .LinkFormat Is Nothing Then
Debug.Print "Unlinking: " & .LinkFormat.SourceFullName
.LinkFormat.BreakLink
End If
End With
Next IShape
End Sub

HTH + CHeers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top