|
Sub 提取括号及其里面的内容()
Dim Matches As Object, Matche As Variant, n%, myString As Range, t As String, t1 As String
Dim reg As Object
Set reg = CreateObject("vbscript.regexp")
Set myString = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
Application.ScreenUpdating = False
t = t & Chr(13)
With reg
.Pattern = "[\((][^\r]+[)\)]"
.Global = True: .IgnoreCase = False: .MultiLine = True
Set Matches = .Execute(myString)
If Not Matches Is Nothing Then
For Each Matche In Matches
n = n + 1
t1 = Matche
If Right(t1, 1) <> Chr(13) Then t1 = t1 & Chr(13)
If InStr(t, vbTab & t1) > 0 Then t1 = "*" & t1
t = t & n & vbTab & t1
Next
End If
End With
Application.ScreenUpdating = True
Set reg = Nothing: Set myString = Nothing
t = "提取到的内容:共" & n & "项" & t
Documents.Add.Content.Text = t
End Sub |
|