|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub CommandButton1_Click()
Dim d As Document, a(), p As Range
Set d = ActiveDocument
Call del(d)
With d.Content
.Collapse 0: .MoveStartWhile Chr(13), -10240
.Text = Empty: .InsertAfter Chr(13)
End With
With d.Content.Find
.Font.Bold = 1
Do While .Execute("*^13*^13", , , 1)
n = n + 1: ReDim Preserve a(n)
With .Parent
a(n - 1) = .Start: .SetRange .End, .End
End With
Loop
End With
a(n) = d.Content.End - 1
For i = n To 1 Step -1
With d.Range(a(i - 1), a(i))
Set p = .Duplicate: .Collapse: .MoveEndUntil Chr(13)
.InsertAfter "(XX)"
.Move 4, 1: .Expand 4: .Cut
p.Collapse 0: p.Paste: p.InsertBefore "——": p.MoveEnd , -1
p.InsertAfter "(YY)"
End With
Next
End Sub
Sub del(doc As Document)
With doc.Content.Find
.Execute "^11", , , 1, , , , , , "^p", 2
.Execute "^p^w", , , 0, , , , , , "^p", 2
.Execute "^w^p", , , , , , , , , "^p", 2
.Execute "^13{2,}", , , 1, , , , , , "^p", 2
End With
End Sub |
|