|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 提取答案()
- Dim wdoc As Document
- Dim Ans(1 To 10)
- Dim i, Str1, Str2, AnsNo, m, n
- Set wdoc = ActiveDocument
- wdoc.Range.Find.Execute _
- findtext:="^32{1,}^13", _
- MatchWildcards:=True, _
- replacewith:="^13", _
- Replace:=wdReplaceAll
-
- With wdoc.Paragraphs
- For i = .Count To 1 Step -1
- With wdoc.Paragraphs(i)
- Str1 = .Range.Text
- ' If InStr(.Range.Text, "参考答案") Then
- ' AnsNo = i
- ' End If
- If Str1 Like "[A-E].*" Then
- m = .Range.Characters.Count
- n = .Range.Characters(m - 1)
- Ans(n) = Left(Str1, 1)
- If Ans(n) = "E" Then
- AnsNo = i + 1
- End If
- If Ans(n) = "A" Then
- Str2 = Join(Ans, "")
- wdoc.Paragraphs(AnsNo).Range.Text = "参考答案:" & Str2 & Chr(13)
- Erase Ans
- AnsNo = 0
- End If
- End If
- End With
- Next
- Selection.HomeKey
- wdoc.Range.Find.Execute _
- findtext:="([.\!])[1-9]^13", _
- MatchWildcards:=True, _
- replacewith:="\1^13", _
- Replace:=wdReplaceAll
- End With
- End Sub
复制代码 |
|