|
楼主 |
发表于 2020-3-28 18:27
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
你的代码我整理出来了,测试没有效果,你看看是不是?
Sub test2()
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
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 .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 |
|