|
大致还算有规律。
就是答案位置不固定,本身也还是新手(正在学习正则表达式),这步多花了点时间。
有的答案在段首,有的在段中,有的在段尾。
此代码已整理好结果,未排序和分类,在答案选项前特意留了个空格,方便文本转表格
word自身带排序功能,排序和分类自己搞吧
- Sub 选择题取答案()
- Dim rng As Range, m As Long, n As Long
- Set rng = ActiveDocument.Content
- With CreateObject("vbscript.regexp")
- .Global = True
- .MultiLine = True
- .Pattern = "^\D.*?\r"
- rng = .Replace(rng, "") '剔除所有不是数字序号开头的段落
- .Pattern = "^\d+|[ “”《》:;:??.、,。\.]"
- rng = .Replace(rng, "") '剔除所有干扰结果的标点符号
- .Pattern = "\(\)|()"
- rng = .Replace(rng, "") '剔除无关的空括号
- .Pattern = "(^.*?)[\(|(]([ABCDE×√]+)[\)|)](.*?)(\r)"
- rng = .Replace(rng, "$1$3$2$4") '将答案移动至段尾
- .Pattern = "(..).*?(..)([ABCDE×√]+)(\r)"
- rng = .Replace(rng, "$1..$2 $3$4") '段落首尾(除答案外)各保留两个字符
- .Pattern = "\r\s*\r"
- rng = .Replace(rng, "") '删除空段
- End With
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|