|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 提取答案()
Dim s1, n&, doc As Document, reg, ss, s, i&, j&, ST&, ED&
Set reg = CreateObject("vbscript.regexp")
reg.Global = True
Set doc = ActiveDocument
With ActiveDocument.Content.Find
.Execute "\(", , , 1, , , , 0, , "(", 2
.Execute "\)", , , 1, , , , 0, , ")", 2
End With
reg.Pattern = "^[一二三四五六七八九十]{1,}、"
With doc
For i = 1 To .Paragraphs.Count
s = .Paragraphs(i).Range.Text
If reg.test(s) Then
s1 = s1 & "|" & i
End If
Next i
s1 = s1 & "|" & .Paragraphs.Count
s1 = Split(s1, "|")
reg.Pattern = "^[0-9]{1,}、"
For i = 1 To UBound(s1) - 2
ss = ss & Chr(13) & .Paragraphs(s1(i)).Range.Text
ss = Left(ss, Len(ss) - 1)
For j = s1(i) + 1 To s1(i + 1) - 1
With .Paragraphs(j).Range
ED = .End
If reg.test(.Text) Then
.End = .Start
.MoveEndUntil "、"
.MoveEnd 1
ss = ss & Chr(13) & .Text
Do
ST = .MoveStartUntil("(")
.MoveStart 1
.MoveEndUntil ")"
If ST = 0 Or .End > ED Then Exit Do
ss = ss & .Text & ";"
.Text = Space(Len(.Text))
Loop
End If
End With
Next j
Next i
ss = ss & Chr(13)
For i = s1(UBound(s1) - 1) To s1(UBound(s1))
With .Paragraphs(i).Range
If reg.test(.Text) Then
.End = .Start
.MoveEndUntil "、"
.MoveEnd 1
End If
ss = ss & .Text
End With
Next i
For i = s1(UBound(s1)) To s1(UBound(s1) - 1) + 1 Step -1
s = ""
With .Paragraphs(i).Range
If reg.test(.Text) = 0 Then
For j = 1 To .ComputeStatistics(1)
s = s & Chr(13)
Next j
.Text = s
End If
End With
Next i
ss = Chr(13) & Chr(13) & "【提取答案:】" & ss
reg.Pattern = ";" & Chr(13)
ss = reg.Replace(ss, Chr(13))
.Range(.Range.End - 1, .Range.End - 1) = ss
End With
End Sub
|
评分
-
1
查看全部评分
-
|