Reputation: 97
I wrote a vbscript (.vbs) to add an image to a word document at a bookmark. I need the document to be accessible so I need to add alt text to the image in the word doc. I appreciate any help. The script below puts the image in a doc, but the .AlternativeText isn't working. Any ideas what I am doing wrong?
Here is the code
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.DisplayAlerts = False
Set doc = objWord.Documents.Open("C:\Test.docx")
On Error Resume Next
Set SHP = doc.Bookmarks("bkm_1").Range.InlineShapes.AddPicture("C:\my_image.png")
Set .AlternativeText = "This is the alt text"
On Error GoTo 0
Call doc.SaveAs2("C:\test_update.docx", 12)
doc.Saved = TRUE
objWord.Quit
Upvotes: 1
Views: 165
Reputation: 5031
When you add your picture, SHP
is set to an InlineShape object:
Set SHP = doc.Bookmarks("bkm_1").Range.InlineShapes.AddPicture("C:\my_image.png")
You just need to specify that object to use its AlternativeText property:
SHP.AlternativeText = "This is the alt text"
Upvotes: 2