|
Sub test1()
Dim s1, s2, n&, doc As Document, reg, ss, s, i&, j&, mh
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
'以下取得各大题起始位置
With doc.Range.Find
.Text = "^13[一二三四五六七八九十]{1,}、"
.MatchWildcards = True
Do While .Execute
n = doc.Range(0, .Parent.End).Paragraphs.Count
s1 = s1 & "|" & n
s2 = s2 & "|" & (.Parent.Start + 1)
Loop
s1 = s1 & "|" & doc.Paragraphs.Count
s2 = s2 & "|" & doc.Range.End
End With
s1 = Split(s1, "|")
s2 = Split(s2, "|")
'以下提取填空、选择、判断题答案
For j = 1 To UBound(s1) - 2
ss = ss & Chr(13) & doc.Paragraphs(s1(j)).Range.Text
ss = Left(ss, Len(ss) - 1)
For i = s1(j) + 1 To s1(j + 1) - 1
s = doc.Paragraphs(i).Range.Text
reg.Pattern = "^[0-9]{1,}、"
If reg.test(s) Then
Set mh = reg.Execute(s)
ss = ss & Chr(13) & mh(0)
reg.Pattern = "[\((].*?[)\)]"
If reg.test(s) Then
Set mh = reg.Execute(s)
For Each s In mh
ss = ss & s
Next s
End If
End If
Next i
Next j
'以下提取简答题答案
s = doc.Range(s2(UBound(s2) - 1), s2(UBound(s2))).Text
reg.Pattern = "([0-9]{1,}、).*?(答:)"
s = reg.Replace(s, "$1$2")
ss = ss & Chr(13) & s
ss = "提取答案:" & ss
With Selection
.EndKey 6
.Text = ss
End With
End Sub
|
评分
-
1
查看全部评分
-
|