glencoe,
I can't explain the range issue because it isn't happening here.
As for the wildcard search it works like this.
The "( )" in the .Text string are wildcard grouping symbols. So we are searching for three groups 1) the opening tag, 2) any text 3) the closing tag.
The "\2" in the .Replacement.Text string simply means to replace what was found (i.e., the opening tag, any text, and the closing tag) with the content of group 2 (i.e., just the text)
The following code will find text tag like this "##Test**"
Notice the closing tag string "\*\*" may look a little odd. This is because "*" in a wildcard search means "anything" where in this case we want to search for the literal "**" so we add the "\" before each literal character.
Hope this helps.
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oSection As Section
Dim oHF As HeaderFooter
Dim oRng As Range, oTextRng As Range
Dim strOTag As String, strCTag As String
strOTag = "##"
strCTag = "\*\*"
For Each oSection In ActiveDocument.Sections
For Each oHF In oSection.Headers
With oHF
If .LinkToPrevious = False Or oSection.Index = 1 Then
Set oRng = oHF.Range
With oRng.Find
.Text = "(" & strOTag & ")(*)(" & strCTag & ")"
.MatchWildcards = True
.Replacement.Text = "\2"
While .Execute(Replace:=wdReplaceOne)
oRng.HighlightColorIndex = wdBrightGreen
oRng.Collapse wdCollapseEnd
Wend
End With
End If
End With
Next oHF
Next oSection
End Sub