An implementation of Visual Basic that is built into Microsoft products.
Hi, SteveD
If you just want to allow X anywhere in the 5 characters, then [0-9XL]{5} already does that. In Word wildcards, [ ] means “any one of these characters” and {5} means “exactly five of them,” so X9937 is a valid match.
If you want X specifically in the first position, then the better pattern is:
.Text = "X[0-9]{4}"
That will match X9937, X1234, and so on, but not values where the X appears later. If you want X or L only at the start, use:
.Text = "[XL][0-9]{4}"
One other small thing: your macro is searching backwards because .Forward = False, and with wdFindStop it stops at the document boundary, so where the cursor is placed can affect whether it finds the match.
Thank you for your patience in reading, I hope this information has been helpful to you.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment."
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.