![]() |
#1
|
|||
|
|||
![]()
I'm looking for a Macro that will use a 'Find and replace' function but for the "alt Text" of an image.
Basically, I'd like to Find and image within a document based on its Alt Text Delete the image Insert a new image Give the new Image its own Alt Text I've looked everywhere and I can't find anything on this, can anyone help me? I don't need any dialog boxes for this, I'd just like to enter the search and replacement criteria inside the code if possible. Thanks in advance ![]() PS: I already have code that will go into the header of my document, insert an image then enter it's alt text value. It's the 'Find' function I'm struggling with. Code:
Sub ReplaceImage() ' ' ReplaceImage Macro ' ' If ActiveWindow.View.SplitSpecial <> wdPaneNone Then ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ ActivePane.View.Type = wdOutlineView Then ActiveWindow.ActivePane.View.Type = wdPrintView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.WholeStory Selection.InlineShapes.AddPicture FileName:= _ "IMAGE_LOCATION", LinkToFile:=False, _ SaveWithDocument:=True Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend Selection.InlineShapes(1).AlternativeText = "ALT_TEXT_VALUE" End Sub Code:
Function getPictureByAltText(altText As String) As InlineShape Dim shape As Variant For Each shape In ThisDocument.InlineShapes If shape.AlternativeText = altText Then getPictureByAltText = shape Exit Function End If Next End Function Sub test() Dim myPic as InlineShape Set myPic = getPictureByAltText("AltText to be searched") myPic.Delete End Sub |
Tags |
vba, word 2013 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
![]() |
bertietheblue | Word VBA | 12 | 11-04-2013 05:35 PM |
![]() |
Jack | Word VBA | 2 | 12-12-2012 09:24 PM |
macro or find/replace | JamesVenhaus | Word | 2 | 02-27-2012 03:34 PM |
Find and Replace Macro - A Better Way | Tribos | Word VBA | 0 | 10-08-2008 03:22 AM |