Replacing "tag" with a picture

P

Pete Lund

Hi -
I have a number of Word documents that contain delimited text strings
with the path and filename of a picture. For example:

<#c:\temp\picture1.jpg#>

I'd like to search the document, find the picture references (based on
the <#...#>) and replace the text with the picture.

Before I open my first VBA book could someone let me know if this is
worth looking into doing? If so, a little push in the right direction
would be greatly appreciated!

Thanks-
Pete
 
D

Doug Robbins

Hi Pete,

It's quite possible to do with VBA. Something like the following should do
it, but first, use Edit>Replace to replace each \ with \\.

Dim tag As Range, fname As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\<#*#\>", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set tag = Selection.Range
Set fname = Selection.Range.Duplicate
fname.End = fname.End - 2
fname.Start = fname.Start + 2
ActiveDocument.Fields.Add Range:=tag, Type:=wdFieldEmpty,
Text:="IncludePicture " & fname
Loop
End With

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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