PDA

View Full Version : Solved: Word VB Help - Setting Alternative Text on Images



narlo
04-24-2013, 04:52 AM
I'm using the following code to replace the image in a folder of over 100 word documents. It works great, but ... when replacing the image I also want to set the Alternative (Alt) Text. I've scoured the net looking for an example and after two days, I've found nothing that directly addresses this and I'm wondering if you would help.


Sub ChangePic()
Dim oFile
oFile = Dir("O:\STUDIO\Brit\Forms-Unpacked\Forms-Unpacked\*.doc")
Do While oFile <> ""
Application.Documents.Open FileName:="O:\STUDIO\Brit\Forms-Unpacked\Forms-Unpacked\" & oFile
With Selection
.GoTo what:=wdGoToGraphic, Count:=1
.Delete
.InlineShapes.AddPicture FileName:="O:\STUDIO\Brit\Logo\dynamic.png"
End With
If ActiveDocument.Saved = False Then ActiveDocument.Save
ActiveDocument.Close
oFile = Dir

narlo
04-24-2013, 04:55 AM
I've tried this but it keeps giving me an error stating that the member could not be found ...
Sub ChangePic()
Dim oFile
oFile = Dir("O:\STUDIO\Brit\Forms-Unpacked\Forms-Unpacked\*.doc")
Do While oFile <> ""
Application.Documents.Open FileName:="O:\STUDIO\Brit\Forms-Unpacked\Forms-Unpacked\" & oFile
With Selection
.GoTo what:=wdGoToGraphic, Count:=1
.Delete
.InlineShapes.AddPicture
FileName:="O:\STUDIO\Brit\Logo\dynamic.png"
.InlineShapes(1).AlternativeText = "SRS_image"
End With
If ActiveDocument.Saved = False Then ActiveDocument.Save
ActiveDocument.Close
oFile = Dir

narlo
04-28-2013, 08:00 AM
I finally figured it out and it works perfectly:


Sub ChangePic()
Dim oFile
oFile = Dir("C:\Users\mlevine\Desktop\Studio Forms\Forms-Working\*.doc")
Do While oFile <> ""
Application.Documents.Open FileName:="C:\Users\mlevine\Desktop\Studio Forms\Forms-Working\" & oFile
With Selection
.GoTo what:=wdGoToGraphic, Count:=1
.Delete
.InlineShapes.AddPicture FileName:="C:\Users\mlevine\Desktop\Studio Forms\SRS_image.jpg"
With ActiveDocument.InlineShapes(1)
.AlternativeText = "SRS_image"
End With
End With
If ActiveDocument.Saved = False Then ActiveDocument.Save
ActiveDocument.Close
oFile = Dir
Loop
End Sub

:thumb