View Single Post
 
Old 02-20-2019, 04:36 AM
MikeForward MikeForward is offline Windows 10 Office 2010
Novice
 
Join Date: Feb 2019
Posts: 10
MikeForward is on a distinguished road
Default Word VBA wildcard search - odd results

Hi there,

I am finding odd results with the following wildcard search in Word 2010 VBA. I am trying to search for special codewords embedded in a Word doc which look like "ZXZABCDEF...". where X is a single character which can be 0-9,A-Z, as are the ABCDEF.... The first and third characters are always Z. The ABCDEF...is a minimum of 3 characters and a maximum of 16 characters.

The following search works correctly in either backwards or forwards direction:
[/code] Selection.Find.ClearFormatting
With Selection.Find
.Text = "<Z[0-9A-Z]Z[0-9A-Z]{3}"
.Replacement.Text = ""
.Forward = bForwards '***where bForwards is a Boolean = true or false
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
b = Selection.Find.Execute[/code]

However, if I change the {3} in the .Text= line to {3,16} the search then works forwards, but fails backwards! Any ideas? Macropod - this is a simplified form of my first question, and does seem to give genuinely odd results. I promise no more questions for a while after this!

Thanks a lot

Mike
Reply With Quote