|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
可试试:
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 |
|