Image 基于图像的Alt文本查找和替换的Word VBA宏
我正在寻找一个宏,它将使用“查找并替换”功能,但用于图像的“alt Text” 基本上,我想Image 基于图像的Alt文本查找和替换的Word VBA宏,image,vba,replace,ms-word,Image,Vba,Replace,Ms Word,我正在寻找一个宏,它将使用“查找并替换”功能,但用于图像的“alt Text” 基本上,我想 基于文档的Alt文本在文档中查找和显示图像 删除图像 插入新图像 为新图像指定自己的Alt文本 我到处都找过了,但找不到任何线索,有人能帮我吗?我不需要任何对话框,如果可能的话,我只想在代码中输入搜索和替换条件 提前感谢:) PS:我已经有代码将进入我的文档标题,插入一个图像,然后输入它的alt文本值。这是我正在努力解决的“查找”功能 Sub ReplaceImage() ' ' ReplaceIm
- 基于文档的Alt文本在文档中查找和显示图像
- 删除图像
- 插入新图像
- 为新图像指定自己的Alt文本
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
Sub-ReplaceImage()
'
'替换图像宏
'
'
如果ActiveWindow.View.SplitSpecial WDPaneOne,则
活动窗口。窗格(2)。关闭
如果结束
如果ActiveWindow.ActivePane.View.Type=wdNormalView或ActiveWindow_
ActivePane.View.Type=wdOutlineView然后
ActiveWindow.ActivePane.View.Type=wdPrintView
如果结束
ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader
健康的选择
Selection.InlineShapes.AddPicture文件名=_
“图像位置”,LinkToFile:=False_
SaveWithDocument:=True
Selection.MoveLeft单位:=wdCharacter,计数:=1,扩展:=wdExtend
Selection.InlineShapes(1).AlternativeText=“ALT\u TEXT\u VALUE”
端接头
要通过alt text搜索图片,可以使用以下功能:
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
Dim myPic as InlineShape
Set myPic = getPictureByAltText("YourAltText")
myPic.Delete
然后像这样使用它:
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
Dim myPic as InlineShape
Set myPic = getPictureByAltText("YourAltText")
myPic.Delete
要按alt text搜索图片,可以使用如下函数:
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
Dim myPic as InlineShape
Set myPic = getPictureByAltText("YourAltText")
myPic.Delete
然后像这样使用它:
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
Dim myPic as InlineShape
Set myPic = getPictureByAltText("YourAltText")
myPic.Delete
所以在他的帮助下,我们找到了问题的症结所在
以下是我自己添加的正确且有效的代码,以消除错误:)
然后:
再次感谢你的帮助 所以在和的帮助下,我们找到了问题的症结所在
以下是我自己添加的正确且有效的代码,以消除错误:)
然后:
再次感谢你的帮助 使用了一段时间后,我让它变得更简单了
Dim pic as InlineShape
Dim alt as String
Alt = "ENTER ALT TEXT HERE"
For Each pic in activedocument.inlineshapes
If pic.AlternativeText = Alt Then
pic.Delete
Exit For
End If
Next
在使用了一段时间之后,我让它变得更简单了
Dim pic as InlineShape
Dim alt as String
Alt = "ENTER ALT TEXT HERE"
For Each pic in activedocument.inlineshapes
If pic.AlternativeText = Alt Then
pic.Delete
Exit For
End If
Next
它不适用于
find>>replace
word功能。您需要有一个宏来检查文档中的每个对象。您是在谈论您想要处理的InlineShapes
仅(嵌入式形状)还是shapes
(浮动形状)或两者?谢谢,我是在谈论InlineShapes我认为@Manu的答案非常接近您的需要。请参见答案下方的我的评论。它不适用于find>>replace
word功能。您需要有一个宏来检查文档中的每个对象。您是在谈论您想要处理的InlineShapes
仅(嵌入式形状)还是shapes
(浮动形状)或两者?谢谢,我是在谈论InlineShapes我认为@Manu的答案非常接近您的需要。请参见我在答案下方的评论。您好,Manu,谢谢您,我得到了“运行时错误'91':未设置对象变量或块变量”,调试将我带到行“myPic.Delete”有什么想法吗?这行中可能缺少一条set指令:set getPictureByAltText=shape
BTW,使用function
@KazJawactivedocument.inlineshapes.count
返回1:((是的,文件中只有一个图像:P)难以置信。这一直是问题所在,我不敢相信我自己没有尝试过。非常感谢你们都是绝对的传奇人物!!!!嗨,Manu,感谢我得到了这个“运行时错误'91':未设置对象变量或带块变量”和“调试”将我带到行“myPic.Delete”“有什么想法吗?这一行可能缺少一条设置指令:设置getPictureByAltText=shape
BTW,+1使用函数@KazJawactivedocument.inlineshapes.count
返回1:(是的,文件中只有一个图像:P)难以置信。这一直都是问题所在,我不敢相信我自己没有试过。非常感谢你们两个都是绝对的传奇人物!!!!