本帖最后由 duquancai 于 2017-5-9 00:52 编辑
Sub 移动答案()
Dim doc As Document, a(), n&, i&, k&
Dim p As Range, s As Range, r As Range
Set doc = ActiveDocument
If Not doc.Content.Find.Execute("【答案】") Then Exit Sub
Call DP(doc.Content)
With doc.Content.Find
Do While .Execute("^13[0-9]{1,}", , , 1)
n = n + 1: ReDim Preserve a(n)
a(n - 1) = .Parent.Start + 1: .Parent.Collapse 0
Loop
End With
a(n) = doc.Content.End
For i = n To 1 Step -1
Set p = doc.Range(a(i - 1), a(i)): Set s = p.Duplicate: Set r = p.Duplicate
With s.Find
If .Execute("[\))]^13", , , 1) Then
s.Collapse: s.MoveStartUntil "((", wdBackward
r.Collapse: k = r.MoveUntil("】"): r.Move , 1: r.MoveEndUntil Chr(13)
If k <> 0 Then
s.FormattedText = r.FormattedText
p.Collapse: p.MoveUntil "【": p.EndOf 4, wdExtend: p.Text = Empty
End If
End If
End With
Next
End Sub
Function DP(selectRange As Range)
sr$ = Chr$(32) & Chr$(9) & ChrW$(12288) & ChrW$(160)
With selectRange
With .Find
.Execute "^11", , , 1, , , , 0, , "^p", 2
.Execute "^p^w", , , 0, , , , 0, , "^p", 2
.Execute "^w^p", , , 0, , , , 0, , "^p", 2
End With
With .Paragraphs(1).Range
n& = Len(.Text) - 1: .SetRange .Start, .Start
If .MoveEndWhile(sr, n) <> 0 Then: .Text = Empty
End With
End With
End Function
|