我想扫描一份报告并突出显示交叉引用。突出显示作为引用的 TypeFields 非常容易。
如何定位引用图像的标题?我不希望它们相互连接(还没有)。
我尝试了
InlineShapes.Caption
,但没有任何结果(InlineShapes
有效,我可以调整大小和删除图像)。InlineShape.Text
提取标题,但没有结果。还有InlineShape.Caption.Text
和InlineShape.CaptionLabel.Text
,它们都是无法识别的物体(如果我没记错的话)。
这是我想出的代码,它查找引用,突出显示它们,以及删除图像。
Sub ReferenceHighlight()
'Define the range as the whole document
Dim docRange As Range
Set docRange = ActiveDocument.Range
'Define all Fields in the Document
Dim fld As Word.Field
'Define an incremental integer
Dim i As Integer
i = 1
'Define all Pictures in the Document
Dim image As InlineShape
For Each image In docRange.InlineShapes
image.Delete
Next image
For Each fld In docRange.Fields
If fld.Type = wdFieldRef Then
fld.Result.HighlightColorIndex = wdYellow
End If
Next fld
End Sub
请尝试一下。
For Each fld In docRange.Fields
If fld.Type = wdFieldRef Then
fld.Select
Selection.Expand xlLine
Selection.Range.HighlightColorIndex = wdYellow
End If
Next fld
Sub HightLightCaption()
Options.DefaultHighlightColorIndex = wdYellow
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("Caption")
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
End Sub