Inserting different pictures

D

David

Hi,

I'm trying to create a macro that finds and replaces words with
pictures (the words correspond to the filenames of pictures that are
saved in one directory).

Filenames are searched for, cut, then pasted into the "Insert Picture"
browser. The problem is that it inserts the same picture each time; I
want the FileName to equal the word that has been cut. Entire code is
pasted below.

Thanks in advance,
David

Selection.Find.ClearFormatting
With Selection.Find
.Text = "%%%"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.InlineShapes.AddPicture FileName:= _
"C:\My Documents\My Pictures\bonebrush.jpg", LinkToFile:=False,
_
SaveWithDocument:=True
End Sub
 
D

Doug Robbins - Word MVP

Your code is adding the same picture all of the time because of this line of
code:

C:\My Documents\My Pictures\bonebrush.jpg

You need to be replacing bonebrush with whatever the filename is on each
occasion.

If the document contains only the names of the pictures, you might be better
off using it as a datasource for a mailmerge:

See the "Graphics from data base" item under the "Special merges" section of
fellow MVP Cindy Meister's website at

http://homepage.swissonline.ch/cindymeister/MergFram.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

David

The document contains pictures and captions related to each picture.
The captions are merged in from Column A in an Excel database, the
pictures' filenames merged from Column B in the same database. So, the
datasource in already there.

Is there some way to set up the macro to paste each filename as it's
copied, rather than automatically inserting the same filename each time
(as it's doing now)?

Thanks,
David
 
D

Doug Robbins - Word MVP

See the information in the link to Cindy's site that I suggested.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

David

Ah! Finally got it to work; I was manually typing the {} characters,
rather than using CTL + F9.

Thanks 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