【发布时间】:2015-02-25 08:50:10
【问题描述】:
我有下面的代码已经在工作,但仍需要微调。它是一个查找通配符搜索字符串的匹配项并突出显示出现的函数。但我相信它仍然可以使用全部替换在一行中完成。我已经尝试了几乎所有我能想到的东西,我认为是时候询问专家了。请告诉我如何以更短的方式做到这一点。任何帮助将不胜感激。谢谢!
Sub findfunction()
If (findHL(activedocument.Range, "[aeiou]")) = True Then MsgBox "Highlight vowels Done", vbInformation + vbOKOnly, "Vowels Highlight Result"
End Sub
Function findHL(r As Range, s As String) As Boolean
Dim rdup As Range
Set rdup = r.Duplicate
rdup.Find.Wrap = wdFindStop
Do While rdup.Find.Execute(findtext:=s, MatchWildcards:=True) = True
If (Not rdup.InRange(r)) Then Exit Do
rdup.HighlightColorIndex = wdBlue
rdup.Collapse wdCollapseEnd
Loop
findHL = True
End Function
【问题讨论】: