我发现的当前VBA代码突出显示了放在常规段落中的列表中的特定单词。但是,我还需要突出显示放置在文本框中的单词。还有关于如何突出显示文本框内文本的想法吗?
Sub HighlightWords()
'
' HighlightWords Macro
'
'
Dim Word As range
Dim WordCollection(2) As String
Dim Words As Variant
WordCollection(0) = "Andres"
WordCollection(1) = "just"
WordCollection(2) = "Pending"
Options.DefaultHighlightColorIndex = wdYellow
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
For Each Word In ActiveDocument.Words
For Each Words In WordCollection
With Selection.Find
.Text = Words
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
Next
End Sub
答案 0 :(得分:0)
您应该使用此循环:
For i = 1 To ActiveDocument.Shapes.Count
ActiveDocument.Shapes(i).Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
' do something...
Next i