I am using RegEx search, for find out the particular word in my MS-Word document, and the search result is stored into a variable. My problem is I want to apply a custom style only for the search result
Input: worldwide[1,2]. Before, during or after the [1,3,4][1,2,4,5] [1,2,6,7,8] [1,2] [1,2]
I am using the following code
Sub RegexReplaces()
Set matches = New regExp
Dim Sure As Integer
Dim rng As Range
matches.Pattern = "([\[\(][0-9, -]*[\)\]])"
matches.Global = True
Dim mat As MatchCollection
Set mat = matches.Execute(ActiveDocument.Range)
For Each m In mat
Sure = MsgBox("Are you sure?" + m, vbOKCancel)
If Sure = 1 Then
m.Style = ActiveDocument.Styles("Heading 1") 'this is the error line
Else
MsgBox "not1111"
End If
Next m
End Sub