Select where to insert new image
Hi all,
This is probably really basic, I have been trawling through information trying to find the answer with no luck. Basically I have an arduous task of changing some text and a picture on over 250 documents. The code I have is as below (obviously text and file path changed)
The top of it works fine, the text replaces, the old picture gets deleted (well replaced with " "). It's the bottom bit as it will pull in the new image at whatever location the cursor is at when the file opens. I was it to be where the old one is, that is half the reason I replaced the photo with " " thinking maybe I can get the cursor to go to " " and then pull the image in but I can't even find how to do that, I'm sure there's a much easier way than the roundabout way I am trying anyway, so any help will be gratefully apricated.
Sub SimpleReplace()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "ABC"
.Replacement.Text = "XYZ"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^g"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.InlineShapes.AddPicture FileName:= _
"C:\FILE PATH", LinkToFile:=False, _
SaveWithDocument:=True
End Sub
|