I am writing a macro to search a document for all instances of [TBR-XXX] and [TBD-YYY] ( X's and Y's are numbers, like 001, 002, etc., and yes, the square brackets are part of the item I'm looking for ). Once I find the instances, I put them into a table along with the corresponding section number from whence they came.
The brackets and the hyphen are throwing me as they are special characters. I've tried the following ( snippet of code ):
Selection.GoTo What:=wdGoToBookmark, Name:="bmStartOfBody" ' Start at the beginning of the main body section
Selection.Collapse
With Selection.Find
.Text = "TB??^#^#^#"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
My document starts with the word, "The" and of course, the .Text search string above picks up on the capital T and thinks that is the first TBR/TBD item. From there, the whole thing breaks down.
I've also tried the following for the .Text string:
"[TB??^#^#^#]" (same result)
"\[TB??^#^#^#\]" (Same result)
"[[]TB??^#^#^#[]]" (Didn't work)
But when I used, "[TBR?^#^#^#]" I found all the TBR values.
I could simply search for the TBR values and then the TBD values, but I'm just curious about the correct way to do the search using a string with the wildcards in there. Hopefully someone can shed some light on this for me. Thanks! By the way, I tried using the ^# with the "Find" feature in word with the "Use Wildcards" selected just to see if I could learn anything from the built in feature, but it said it can't use the ^# wildcard in a find using the built in feature. Ugh.