|
参考http://club.excelhome.net/thread-993054-1-1.html中sqhsqhli的代码,再给出以下代码,请测试。
Sub 把文档尾段答案逐一写入题干()
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 Left(a(i), 1)
.Parent.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
Sub 把单选题各题答案按题号提取到文档末尾()
Dim i%
ActiveDocument.Content.Find.Execute findtext:="^32", replacewith:="", Replace:=wdReplaceAll
ActiveDocument.Range.InsertAfter Chr(13) & "整理的答案是:"
With ActiveDocument.Content.Find
.Text = "[\((][A-Z]"
.Forward = True
.MatchWildcards = True
Do While .Execute
i = i + 1
ActiveDocument.Range.InsertAfter i & "、" & Right(.Parent.Text, 1) & vbTab
ActiveDocument.Range(.Parent.End - 1, .Parent.End) = ""
.Parent.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub |
|