楼主,下午我给你的代码我在 Word2003 下测试正常!回到家后又想了想,觉得弄复杂了,仅用强大的《查找和替换》即可实现,第二种解法如下,测试正常,请测试:
- Sub test试卷题目与答案分开()
- Dim y$
- y = ActiveDocument.Name
- Selection.WholeStory
- Selection.Copy
- Documents.Add.Content.Paste
- Selection.EndKey 6
- Selection.TypeText Text:="【题目】"
- ActiveDocument.Content.Find.Execute "(【解析】*)(【题目】)", , , 1, , , , , , "\2", 2
- ActiveDocument.Content.Find.Execute "(【答案】*)(【题目】)", , , 1, , , , , , "\2", 2
- ActiveDocument.Paragraphs.Last.Range.Delete
- ActiveDocument.Content.InsertAfter Text:=vbCr & vbCr & "参考答案" & vbCr & vbCr
- Documents(y).Activate
- ActiveDocument.Content.Find.Execute "(【题目】)([0-9]{1,}、)(*)(【答案】)", , , 1, , , , , , "\2\4", 2
- ActiveDocument.Content.Copy
- ActiveDocument.Close savechanges:=wdDoNotSaveChanges
- Selection.EndKey 6
- Selection.Paste
- Selection.HomeKey 6
- ActiveDocument.Characters(1).Copy
- MsgBox "处理完毕!!!尚未保存!!!", 0 + 48
- End Sub
复制代码
|