Replacing selected text with a picture?

T

Tony Kirk

Hello all,

I've been trying to find a simple solution to finding variables in a
word2k document and then replacingthat variable with an image. *Is* there a
simple solution for this that anyone knows of? I came across a rather
complex solution that was a page of code and only worked %80 of the time. It
isn't even worth posting to try and get fixed.

Regards,
-Tony Kirk
 
J

JGM

Hi Tony,

Play around with the following macro:

'_______________________________________
Sub Replace_String_Image()

Dim Message As String
Dim Title As String
Dim Default As String
Dim UserText As String
Dim PixPathandName As String
Dim CurrentRange As Range

PixPathandName = "D:\YourPath\Image.jpg"
Set CurrentRange = Selection.Range

Selection.HomeKey wdStory

Message = "What text do you want to replace by a picture?"
Title = "Replace text by picture"
Default = "Your text"

UserText = InputBox(Message, Title, Default)

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
Do While .Execute(FindText:=UserText) = True
Selection.InlineShapes.AddPicture FileName:=PixPathandName, _
LinkToFile:=False, SaveWithDocument:=True
Loop
End With

CurrentRange.Select

End Sub
'_______________________________________

HTH
Cheers!
 

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