#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Hi! Catch it:
Code:
Sub Replace_Pic() selection.Find.ClearFormatting selection.Find.Replacement.ClearFormatting With selection.Find .text = "^g" .MatchWildcards = False .Execute If .found Then selection.InlineShapes.AddPicture filename:= _ "d:\Desktop\2.jpg", LinkToFile:=False, _ SaveWithDocument:=True End If End With End Sub |
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
Thanks for your thanks!
Note that this code raplaces a single picture. If you want to replace multiple pictures with the same image, the code should include backward looping. |
#5
|
|||
|
|||
Understood. There is only one image on the page so this one works fine. I have also posted another query. I am unsure if you can help
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Select Image and Move to Front | Pestomania | Word VBA | 1 | 12-24-2020 09:07 AM |
Word 2007-cannot select or copy image | calvin-c | Word | 2 | 01-05-2017 02:26 PM |
ComboBox : select image to insert in Sheet1 | smallxyz | Excel Programming | 0 | 02-07-2016 05:41 PM |
Select an entire line (to insert one) | Officer_Bierschnitt | Excel Programming | 3 | 11-06-2015 03:05 AM |
Background image vs. insert image | lilaria | PowerPoint | 0 | 04-18-2011 08:45 AM |