|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
可试试:
Sub test2()
Dim aPar As Paragraph, TF As Boolean
Dim temp As String, num As Integer, i As Integer, info As String
On Error Resume Next
Application.ScreenUpdating = False
'ActiveDocument.Fields.Unlink
For Each aPar In ActiveDocument.Paragraphs
With aPar.Range.Find
.ClearFormatting
.Font.Color = wdColorRed
.Format = True
Do While .Execute
TF = True
temp = temp & .Parent & " "
.Parent.SetRange .Parent.End, .Parent.Paragraphs(1).Range.End - 1
Loop
If TF = True Then
num = Int(Val(aPar.Range.Text))
Do While num = 0
i = i + 1
num = Int(Val(aPar.Previous(i).Range.Text))
If i > 10 Then Exit Do '预防死循环
Loop
info = info & num & "." & Trim(temp) & vbCrLf
TF = False
temp = ""
i = 0
End If
End With
Next
'ActiveDocument.Undo
Documents.Add.Content = info
ActiveDocument.Content.Find.Execute "^p0.", replacewith:=" ", Replace:=wdReplaceAll
Application.ScreenUpdating = True
End Sub |
|