copy all images?

A

alenhart

I am hoping to figure out how to select and copy all images in a
document using vba.

the images are all inline, and the whole purpose is that they need to
be pasted in as gifs (they are currently linked to the data source).
any thoughts on the best way to do this?

thanks

anne
 
J

Jezebel

Copying and pasting won't do that. You'll need to iterate the links and
individually read the link address (and if necessary make a note of the
displayed size), then delete the field and insert the picture at that point,
something like this ---

Dim pAddress As String
Dim pHeight As Double
Dim pIndex1 As Long
Dim pIndex2 As Long
Dim pIShape As Word.InlineShape
Dim pRange As Word.Range
Dim pWidth As Double

'Iterate the loop backwards, so as not to re-process the newly inserted
pictures
For pIndex1 = ActiveDocument.InlineShapes.Count To 1 Step -1

'Get a reference to the picture
Set pIShape = ActiveDocument.InlineShapes(pIndex1)

'Skip it if there's no field (ie it's not linked)
If Not pIShape.Field Is Nothing Then

'Get the details, then delete it
With pIShape
Set pRange = .Range
pHeight = .Height
pWidth = .Width
pAddress = .Field.Code
.Delete
End With

'Extract the file name from the field code
pIndex2 = InStr(pAddress, Chr(34))
pAddress = Mid$(pAddress, pIndex2 + 1)
pIndex2 = InStr(pAddress, Chr(34))
pAddress = Left$(pAddress, pIndex2 - 1)
pAddress = Replace$(pAddress, "\\", "\")

'Insert the picture and set its size
With ActiveDocument.InlineShapes.AddPicture(FileName:=pAddress,
LinkToFile:=False, Range:=pRange)
.Height = pHeight
.Width = pWidth
End With

End If
Next
 
A

alenhart

this is perfect. It was working if I went to copy, paste special, paste
as... but this is twenty times easier.
thank you so much!
 

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