0

我正在尝试创建一个宏,它将搜索文档并突出显示每个出现的空格,单词“for”,然后使用来自该站点的修改代码,然后像这样的另一个空格“for”,我得到了这个:

Sub findfunction()
If (findHL(ActiveDocument.Content, "[ for ]")) = True Then MsgBox "Highlight Comma's and Coordinating Conjunctions Done", vbInformation + vbOKOnly, "Highlight Result"
End Sub

Function findHL(r As Range, s As String) As Boolean
Options.DefaultHighlightColorIndex = wdYellow
r.Find.Replacement.Highlight = True
r.Find.Execute MatchWholeWord:=True, FindText:=s, MatchWildcards:=True, Wrap:=wdFindContinue, Format:=True, replacewith:="", Replace:=wdReplaceAll
findHL = True
End Function

问题是它只突出显示字母 f、o 和 r 的每一次出现。我希望它仅在找到序列“ for”时突出显示,而不是单个字符。我是新手,我不确定从这里去哪里,所以任何帮助将不胜感激。感谢:D

4

1 回答 1

0

通配符不是必需的。搜索字符串应该是“for”和 MatchWildcards:=False。

Sub findfunction()
    If (findHL(ActiveDocument.Content, " for ")) = True Then
        MsgBox "Highlight Comma's and Coordinating Conjunctions Done", vbInformation + vbOKOnly, "Highlight Result"
    End If
End Sub

Function findHL(r As Range, s As String) As Boolean
    Options.DefaultHighlightColorIndex = wdYellow
    r.Find.replacement.Highlight = True
    r.Find.Execute MatchWholeWord:=True, FindText:=s, MatchWildcards:=False, Wrap:=wdFindContinue, Format:=True, replacewith:="", Replace:=wdReplaceAll
    findHL = True
End Function
于 2013-08-20T09:01:23.453 回答