|
- Sub Find_ActiveDocument_通用()
- '全文查找:不激活对象,不选定文字内容,查找前后光标不动,速度极快!
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = "" '此处自定义查找内容
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .Select '确定查找对象是否正确(用后屏蔽或删除此语句)
- End With
- Loop
- End With
- End Sub
- Sub Find_Selection_通用()
- '全文查找:激活对象,选定文字内容,查找前后光标移动,速度一般较慢!
- With Selection
- .HomeKey Unit:=wdStory
- With .Find
- .ClearFormatting
- .Text = "[0-9]{1,}" '此处自定义查找内容
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .Font.Color = wdColorRed '红色(设置格式)
- End With
- Loop
- End With
- End With
- End Sub
- Sub Find_Range_通用()
- '区域查找:不激活对象,仅在选定区域内查找文字,速度较快!
- Dim r As Range, a As Range
- With Selection
- Set r = .Range
- Set a = .Range
- End With
- With r.Find
- .ClearFormatting
- .Text = "[0-9]{1,}" '此处自定义查找内容
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .Font.Color = wdColorRed '红色(设置格式)
- .SetRange Start:=.End, End:=a.End
- End With
- Loop
- End With
- End Sub
- Sub Find_循环遍历所有段落()
- Dim i As Paragraph
- For Each i In ActiveDocument.Paragraphs
- With i.Range
- If .Text Like "*[0-9]*" Then .Font.Color = wdColorRed '此行自定义
- End With
- Next
- End Sub
- Sub Find_循环遍历选定区域()
- Dim i As Paragraph
- For Each i In Selection.Paragraphs
- With i.Range
- If .Text Like "*[0-9]*" Then .Font.Color = wdColorRed '此行自定义
- End With
- Next
- End Sub
复制代码 |
|