adding text before and after an image

R

rani

i have to add a text <image> before all the images and </image> after all the
images in a MS word doc using VBA coding.

can anyone help me with its code?
 
J

Jezebel

Dim pShape as Word.Shape
For each pShape in ActiveDocument.InlineShapes
with pShape.Range
.InsertBefore "<image>"
.InsertAfter "</image">
end with
Next

This assumes that your images are inline (rather than floating). If they're
floating, you'll need to provide more info about the intended result.
 
R

rani

Dear Jezebel
thanks for your help. i tried your code but it is not working. it shows some
error in the third line of your code. it selects ".range" and gives a message
that data member not found.
 
H

Helmut Weber

Hi Rani,
Dim pShape as Word.InlineShape
.InsertAfter "</image>"

It's cheap, of course,
to correct a minor mistake and a typo.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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