如何使用vba搜索并突出显示单词列表 [英] how do I search and highlight a list of words in word using vba
问题描述
如何使用VBA搜索和突出显示Word中列表中的单词? 例如,我如何能够搜索并突出显示文档中的以下单词: am,is,are,was,are,being,be or or been?
How do I search and highlight words from a list in Word using VBA? For example, how would I be able to search for and highlight the following words in a document: am, is, are, was, were, being, be, or been?
推荐答案
试试这个:
Sub HighlightWords()
Dim itm As Variant
Application.ScreenUpdating = False
Options.DefaultHighlightColorIndex = wdYellow
使用ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
对于每个itm In Array("am","is is","是","是","是","是","是","是","是",")
.Execute FindText:= itm,ReplaceWith:= itm,Replace:= wdReplaceAll
接下来它是
结束与$
Application.ScreenUpdating = True
End Sub
Sub HighlightWords()
Dim itm As Variant
Application.ScreenUpdating = False
Options.DefaultHighlightColorIndex = wdYellow
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
For Each itm In Array("am", "is", "are", "was", "were", "being", "be", "been")
.Execute FindText:=itm, ReplaceWith:=itm, Replace:=wdReplaceAll
Next itm
End With
Application.ScreenUpdating = True
End Sub
这篇关于如何使用vba搜索并突出显示单词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!