英文:
Add image to word with alt text using VBScript
问题
我编写了一个vbscript(.vbs)来将图像添加到Word文档中的书签位置。我需要文档可访问,所以我需要在Word文档中的图像上添加替代文本。我感谢任何帮助。下面的脚本将图像放入文档中,但.AlternativeText未起作用。我做错了什么?
以下是代码:
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")
SHP.AlternativeText = "这是替代文本"
On Error GoTo 0
Call doc.SaveAs2("C:\test_update.docx", 12)
doc.Saved = True
objWord.Quit
英文:
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
答案1
得分: 2
当您添加图片时,SHP
被设置为一个 InlineShape 对象:
Set SHP = doc.Bookmarks("bkm_1").Range.InlineShapes.AddPicture("C:\my_image.png")
您只需要指定该对象以使用其 AlternativeText 属性:
SHP.AlternativeText = "这是替代文本"
英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论