|
本帖最后由 QQ214189912 于 2020-3-29 09:07 编辑
- Sub test26()
- Dim rng As Range, myrange As Range, inti As Integer
- Dim istr01 As String, istr02 As String, istr03 As String
- Dim dic As Object, myRegExp As Object, mhs As Object
- Dim ky As Variant, tm As Variant
- Set dic = CreateObject("scripting.dictionary")
- Set myRegExp = CreateObject("Vbscript.RegExp")
- With ActiveDocument
- For inti = 1 To .Paragraphs.Count
- Set rng = .Paragraphs(inti).Range
- Set myrange = .Paragraphs(inti).Range
- With rng
- myRegExp.MultiLine = True
- myRegExp.Pattern = "(^\d{1,}\.).*"
- If myRegExp.test(.Text) Then
- Set mhs = myRegExp.Execute(.Text)
- If mhs.Count = 0 Then Exit Sub
- istr01 = mhs(0).submatches(0)
- With .Find
- .ClearFormatting
- .Font.Underline = wdUnderlineWavy
- Do While .Execute
- If Not .Parent.InRange(myrange) Then Exit Do
- istr02 = .Parent.Text
- If dic.Exists(istr01) Then
- dic(istr01) = dic(istr01) & Space(2) & istr02
- Else
- dic(istr01) = istr02
- End If
- Loop
- End With
- End If
- End With
- Next
- End With
- ky = dic.keys
- tm = dic.items
- For inti = LBound(ky) To UBound(ky)
- istr03 = istr03 & ky(inti) & tm(inti) & Chr(13)
- Next
- Documents.Add.Content.Text = istr03
- End Sub
复制代码 |
|