Hi i have the codes below that is already working perfectly. What i can't figure out is how to count the number of times a wildcard search finds a match. Can anyone tell me how i can go about this? The codes are a开发者_Python百科s follows:
Sub findfunction()
If (findHL(activedocument.Content, "[aeiou]")) = True Then MsgBox "Highlight vowels Done", vbInformation + vbOKOnly, "Vowels Highlight Result"
If (findHL(activedocument.Range, "<wa*>")) = True Then MsgBox "Highlight words beginning with WA", vbInformation + vbOKOnly, "Prefix Find Result"
End Sub
Function findHL(r As Range, s As String) As Boolean
Options.DefaultHighlightColorIndex = wdRed
r.Find.Replacement.highlight = True
r.Find.Execute FindText:=s, MatchWildcards:=True, Wrap:=wdFindContinue, Format:=True, replace:=wdReplaceAll
findHL = True
End Function
Any help would greatly be appreciated. Thanks guys!
I think you just need a static Counter field defined at the top of your module - i.e. not within any sub or function (which is what makes it static):
dim MatchCounter as long
Just initialize to zero at the appropriate place and have your matching function increment on each match. (Could also wrap this in a small Class if the initialization logic / update logic is spread around & hard to pin down).
精彩评论