|
文件不经过规整怎么进行处理,反正大概就是这个思路,也不难就是了。不用VBA也行!
没做错误处理,只做了一个死循环跳出,让你输入数字你别输入一个超过两位的正整数。2010通过。
就是下面那个文件。
- Sub Key()
- '----key1----
- Dim bTxt As String '被替换的
- Dim yTxt As String '替换为
- bTxt = "(〖答案〗*)^13(〖考点〗*)^13"
- yTxt = "\1\2"
- With Selection.Find
- .ClearFormatting '清除替换的格式
- .Replacement.ClearFormatting '清除替换为的格式
- .Text = bTxt '被替换的文本
- .Replacement.Text = yTxt '替换为的文本
- .Forward = True '向前搜索
- .MatchWildcards = True '使用通配符
- '.Style '样式对象
- '.Replacement '要替换的对象
- .Wrap = wdFindContinue '继续搜索
- .Execute Replace:=wdReplaceAll
- End With
- '----key2----
- Selection.SetRange 0, 0
- Dim i%, i2%
- Dim n%
- Dim newText As String
- i = CLng(InputBox("请输入初始编号(没做错误处理!):"))
- i2 = i
- With Selection.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Forward = False
- .MatchWildcards = True
- .Text = "〖[0-9]{2}"
- .Replacement.Text = ""
- .Forward = True
- Do While .Execute = True
- n = n + 1
- With Selection
- newText = CStr(i) & ". "
- .InsertBefore newText
- .Next(wdParagraph, 2).Select '如果不选中,则选取不会移动
- .Collapse
- End With
- i = i + 1
- If n = 10 Then Exit Do
- Loop
- End With
- '----key3----
- Selection.SetRange 0, 0
- Dim sTest As String, sAnswer As String
- n = 0
- With Selection.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Forward = False
- .MatchWildcards = True
- .Text = "[0-9]{1,2}. 〖[0-9]{2}*〖答"
- .Replacement.Text = ""
- .Forward = True
- Do While .Execute = True
- n = n + 1
- With Selection
- sTest = sTest & Left(.Range.Text, Len(.Range.Text) - 2)
- .Next wdParagraph, Count:=2
- sAnswer = sAnswer & CStr(i2) & ". " & .Paragraphs(.Paragraphs.Count).Range.Text
- i2 = i2 + 1
- End With
- If n = 10 Then Exit Do
- Loop
- End With
- With Selection
- .Start = ActiveDocument.Range.End
- .InsertAfter vbCrLf & vbCrLf & "____问题____" & vbCrLf & sTest
- .Start = ActiveDocument.Range.End
- .InsertAfter vbCrLf & "____答案____" & vbCrLf & sAnswer
- .SetRange 0, 0
- End With
- End Sub
复制代码
160309关于试题排版的例子.zip
(13.98 KB, 下载次数: 50)
|
|