本帖最后由 weiyingde 于 2020-2-12 12:15 编辑
1、将文档简单处理,提出答案到文尾。
Sub 取答案()
'预处理:删除汉字之间的空格、括号内的空格、空行。
Dim isr As String
With ActiveDocument.Content
.Find.Execute "([一-龥]@)([ ]@)([一-龥]@)", , , 1, , , 1, , , "\1\3", 2
.Find.Execute "([\((])(*)([A-Z])(*)([\))])", , , 1, , , 1, , , "\1\3\5", 2 '删去括号内的空格,"([\((])(^32@)([A-Z])(^32@)([\))])"不能匹配,因为@代表一个以上。
.Find.Execute "^11", , , 1, , , 1, , , "^p", 2
.Find.Execute "^13^13", , , 1, , , 1, , , "^p", 2
.Find.Execute "[ ]{2,}", , , 1, , , 1, , , " ", 2
With .Find
Do While .Execute("[((][A-Z][))]", , , 1, , , 1)
N = N + 1
isr = isr & N & "." & Mid(.Parent.Text, 2, 1) & " "
Loop
isr = "答案:" & isr
End With
With ActiveDocument
With .Range(.Range.End - 1, .Range.End - 1)
.InsertAfter vbCr
.InsertAfter isr
End With
End With
End With
ActiveDocument.Content.Find.Execute "([((])([A-Z])([))])", , , 1, , , 1, , , "\1 \3", 2
End Sub |