MS-Word ドキュメント内の特定の単語を見つけるために RegEx 検索を使用しています。検索結果は変数に格納されます。私の問題は、検索結果だけにカスタム スタイルを適用したいことです。
入力: 世界中[1,2]。[1,3,4][1,2,4,5] [1,2,6,7,8] [1,2] [1,2] の前、最中、または後
次のコードを使用しています
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