Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add image to word with alt text using VBScript

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading