Try something like:
Sub FormatBetweenTags()
Dim startTag As String
Dim endTag As String
Dim x As Integer
Dim y As Integer
startTag:
startTag = InputBox("Enter the start tag (e.g., < )", "Start Tag")
If Len(startTag) < 1 Then
If MsgBox("You did not enter a start tag. Please press OK to go back" _
& " and enter a start tag or press CANCEL to exit.", vbOK +
vbExclamation, _
"Invalid Entry") = vbOK Then
GoTo startTag
Else
Exit Sub
End If
End If
x = Len(startTag) - 1
endTag:
endTag = InputBox("Enter the end tag (e.g., & > )", "End Tag")
If Len(endTag) < 1 Then
If MsgBox("You did not enter an end tag. Please press OK to go back" _
& " and enter a end tag or press CANCEL to exit.", vbOK +
vbExclamation, _
"Invalid Entry") = vbOK Then
GoTo endTag
Else
Exit Sub
End If
End If
y = Len(endTag) - 1
FormatBetweenTags startTag, endTag, x, y
'FormatIncludingTags startTag, endTag
End Sub
Sub FormatBetweenTags(startTag$, endTag$, x As Integer, y As Integer)
Dim oRng As Range
Dim myRange As Range
Dim i As Long
Resetsearch
Set oRng = ActiveDocument.Range
ActiveDocument.Range(0, 0).Select
With oRng.Find
.Text = startTag$
.Wrap = wdFindStop
While .Execute
i = oRng.End
oRng.Collapse direction:=wdCollapseEnd
.Text = endTag$
If .Execute Then
Set myRange = oRng.Duplicate
myRange.Start = i - x
myRange.End = oRng.Start + y
myRange.Font.Italic = True
.Text = startTag$
oRng.Collapse direction:=wdCollapseEnd
oRng.Select
End If
Wend
End With
End Sub
Sub Resetsearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub