|
- Sub 查找替换()
- Set dic = VBA.CreateObject("scripting.dictionary")
- Set reg = VBA.CreateObject("vbscript.regexp")
- Selection.StartOf unit:=wdStory
- With Selection.Find
- .Wrap = wdFindStop
- .Text = "答案"
- If .Execute = False Then
- MsgBox "没有答案"
- Exit Sub
- End If
- Set rng = .Parent
- rng.EndOf unit:=wdStory, Extend:=wdExtend
- ss = rng
- rng.Delete
- With reg
- .Global = True
- .ignorecase = True
- .Pattern = "(\d+).*?([a-z])"
- Set ss = .Execute(ss)
- For Each mm In ss
- dic(mm.submatches(0)) = mm.submatches(1)
- Next
- End With
- End With
- Selection.EndOf unit:=wdStory
- With Selection.Find
- .MatchWildcards = True
- .Forward = False
- .Wrap = wdFindStop
- .Text = "[0-9]{1,}.*[A-Z]."
- Do While .Execute
- Set rng = .Parent
- arr = Split(rng, ".")(0)
- rng.EndOf unit:=wdLine, Extend:=wdExtend
- rng.End = rng.End - 1
- rng.InsertAfter vbCrLf & "答案:" & dic(arr)
- rng.Collapse
- Loop
- End With
- Set dic = Nothing
- Set reg = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|