如何使用vba搜索并突出显示单词列表 [英] how do I search and highlight a list of words in word using vba

查看:83
本文介绍了如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆