|
本帖最后由 wx486 于 2013-7-3 11:50 编辑
ww0000 发表于 2013-7-3 11:27
第10题以后的答案后面会多一个数字
今天专门给你服务了。
Sub 把文档尾段答案逐一写入题干2()
Dim a, i As Integer
ActiveDocument.Content.Find.Execute findtext:="^32", replacewith:="", Replace:=wdReplaceAll
a = Split(ActiveDocument.Paragraphs.Last.Range, "、")
'ActiveDocument.Paragraphs.Last.Range.Delete
With ActiveDocument.Content.Find
.Text = "[\((][\))]"
.Forward = True
.MatchWildcards = True
Do While .Execute
i = i + 1
If i > UBound(a) Then
MsgBox "题目与答案不一致,将退出"
Exit Sub
End If
ActiveDocument.Range(.Parent.End - 1, .Parent.End - 1).InsertAfter Mid$(a(i), 1, Len(a(i)) - 1)
.Parent.Collapse Direction:=wdCollapseEnd
Loop
End With
With ActiveDocument.Content.Find
.Text = "([A-Z]@)([0-9]@)([\))])"
.Replacement.Text = "\1\3"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
Sub 把文档尾段答案逐一写入题干()
Dim reg As Object, j%
Set reg = CreateObject("vbscript.regexp")
With reg
.Global = True
.Pattern = "[A-Z]+(?=[\d+\s])"
.multiline = True
Set matches = .Execute(ActiveDocument.Paragraphs.Last.Range)
End With
Set reg = Nothing
With CreateObject("vbscript.regexp")
.Global = True
.multiline = True
j = 0
Do While j < matches.Count
For Each para In ActiveDocument.Paragraphs
.Pattern = "[(/(]\s*[)/)]"
If .test(para.Range) = True Then
para.Range = .Replace(para.Range, "(" & matches.Item(j) & ")")
j = j + 1
End If
Next
Loop
End With
End Sub
|
|