Finding and converting linked pictures in a Word doc with VB.

C

Chrisso

Hi All

How can I write a program to scan a Word file and for each picture
found determine whether it is embedded or linked to a file? (in the
Insert Picture dialog box, click the arrow next to Insert, and then
click Link to File).

I then need to convert the linked picture to an embedded picture.

Is this possible. I can see how to ask a Picture/Shape if it is
linked.

Chris
 
C

Chrisso

Last lines should have read:

Is this possible? I *cannot* see how to ask a Picture/Shape if it is
linked.

Chrisso
 
C

Cindy M.

Hi Chrisso,
How can I write a program to scan a Word file and for each picture
found determine whether it is embedded or linked to a file? (in the
Insert Picture dialog box, click the arrow next to Insert, and then
click Link to File).

I then need to convert the linked picture to an embedded picture.

Is this possible. I can see how to ask a Picture/Shape if it is
linked.
Which version of Word?

In principle, you should be able to loop the Shapes collection (and
possibly the InlineShapes, as well), picking up the LinkedFormat
property of the graphic. From that, you can get all kinds of
information, and you can break the link. I say "in principle" because
in very early versions of Word it doesn't always work reliably.

Here's a bit of sample code that shows how to work with the LinkFormat
object:

Dim shp As Word.Shape
Dim lf As Word.LinkFormat

Set shp = ActiveDocument.Shapes(1)
Set lf = shp.LinkFormat
If Not lf Is Nothing Then
Debug.Print lf.Type
lf.BreakLink
Else
Debug.Print "Not linked"
End If


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

Chrisso

Hi Cindy

Thanks much for your message. I was really stuck there for awhile.

I am using Word 2003.

The code you supplied does the job I want - thanks very much.

My code based on yours is below.

Chrisso

Option Explicit

Dim miNumLinkedPicsFound As Integer

Sub Runner()
miNumLinkedPicsFound = 0
Shapes_Linked_To_Pictures
InLine_Shapes_Linked_To_Pictures
Debug.Print "miNumLinkedPicsFound: " & miNumLinkedPicsFound
End Sub

Sub Shapes_Linked_To_Pictures()
Dim shp As Word.Shape, lf As Word.LinkFormat
For Each shp In ActiveDocument.Shapes
' If InStr(shp.Name, "Picture") > 0 Then
If True Then
Set lf = shp.LinkFormat
If Not lf Is Nothing Then
' shp.Select
' Stop
If lf.Type = wdLinkTypePicture Then
Debug.Print shp.Name & " is linked to a picture."
miNumLinkedPicsFound = miNumLinkedPicsFound + 1
Else
' Debug.Print shp.Name & " is linked to something
else. " & lf.Type
End If
lf.BreakLink
Else
' ## Debug.Print shp.Name & " is NOT linked"
End If
End If
Next shp
End Sub

Sub InLine_Shapes_Linked_To_Pictures()
Dim shp As Word.InlineShape, lf As Word.LinkFormat
For Each shp In ActiveDocument.InlineShapes
' If InStr(shp.Name, "Picture") > 0 Then
If True Then
Set lf = shp.LinkFormat
If Not lf Is Nothing Then
' shp.Select
' Stop
If lf.Type = wdLinkTypePicture Then
Debug.Print " InLine Shape linked to a picture."
miNumLinkedPicsFound = miNumLinkedPicsFound + 1
Else
' Debug.Print shp.Name & " is linked to something
else. " & lf.Type
End If
lf.BreakLink
Else
' ## Debug.Print shp.Name & " is NOT linked"
End If
End If
Next shp
End Sub
 

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