|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test_main_findStr()
- Dim doc As Document, Rng As Range
- Set doc = ActiveDocument: Set Rng = doc.Content
- With Rng.Find
- .Text = "[A-D]项,[!^13]{1,}"
- .MatchWildcards = True
- Do While .Execute
- If .Parent.Start = .Parent.Paragraphs(1).Range.Start Then
- If Right(Trim(.Parent.Text), 4) = ",错误;" Then
- Call test_insertStr(.Parent, "错误;", .Parent.Characters(1).Text)
- ElseIf Right(Trim(.Parent.Text), 4) = ",正确;" Then
- Call test_insertStr(.Parent, "正确;", .Parent.Characters(1).Text)
- End If
- ElseIf doc.Range(.Parent.Paragraphs(1).Range.Start, .Parent.Paragraphs(1).Range.Start + 6).Text = "解析:A项," Then
- If Right(Trim(.Parent.Text), 4) = ",错误;" Then
- Call test_insertStr(.Parent, "错误;", .Parent.Characters(1).Text)
- ElseIf Right(Trim(.Parent.Text), 4) = ",正确;" Then
- Call test_insertStr(.Parent, "正确;", .Parent.Characters(1).Text)
- End If
- End If
- .Parent.Start = .Parent.End
- Loop
- End With
- msgbox "done"
- End Sub
- Sub test_insertStr(myRng As Range, findStr$, insertStr$)
- Dim doc As Document, insertRng As Range
- Set doc = ActiveDocument
- Set insertRng = doc.Range(myRng.Start + InStrRev(myRng.Text, findStr) - 1, myRng.End)
- insertRng.InsertBefore insertStr
- '最后一句可以不要
- insertRng.Font.ColorIndex = wdRed
- End Sub
复制代码
今天比较有空,又写了一个比较成熟的,坑也比较少的!你可以试试! |
评分
-
2
查看全部评分
-
|