office word利用VBA给指定的多个字符字体批量标红加粗

office word利用VBA给指定的多个字符字体批量标红加粗
场景说明:比如我有一个英文的word文档,无需要把不认识的单词标成红色并且加粗,如果一个一个替换太麻烦,我想到用vba来实现 ,例如我要把abandon、abbreviation、abide、abiding、able、abnormal、aboard、abroad几个在文档中出现的单词标红加粗,我先定义一个字符strarr = "abandon |abbreviation |abide |abiding |able |abnormal |aboard |abroad " 单词用|线分割。
例子如下

Sub biaohong()
Dim strarr As String

strarr = "abandon |abbreviation |abide |abiding |able |abnormal |aboard |abroad "
a = Split(strarr, " ")
b = UBound(a)

  For i = 0 To b
         
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Bold = True
        .Color = wdColorRed
    End With
    With Selection.Find
        
         
        .Text = a(i)
        .Replacement.Text = a(i)
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i
End Sub

你可能感兴趣的:(VBA技术)