|
我的一个自定义函数 单向查找 可以满足你的要求,你自己模仿一下改写代码就行
Sub 删除Word文档中没有数字的句子()
Dim t
Dim l, j, k As Long
Dim str As String
Dim rng As Range
t = Timer
k = 0
Selection.HomeKey 6
Do While 单向查找("[,;。]", True, True)
j = Selection.Range.End
CZ l, j
Set rng = Selection.Range
str = rng.Text
' If 单向查找(" ", True, True) Then
CZ l, j
If Not 单向查找("[1-9]", True, True) Then
If Not str = "与上次汇总数相比," Then
rng.Font.ColorIndex = 6
k = k + 1
End If
End If
' End If
Selection.Collapse 0
l = j
CZ j, j
Loop
MsgBox "运行时间(s):" & Timer - t & vbCr & "已经标记要删除的" & k & "句话!"
End Sub
Function 单向查找(文本, 通配符, 向下)
Dim rng As Range
With Selection.Find
.ClearFormatting
.Text = 文本
.Forward = 向下
.Wrap = wdFindStop '单向查找
' wdFindContinue '往复查找
.MatchWildcards = 通配符
.Execute
.Parent.Select
单向查找 = .Found
End With
End Function
Function CZ(l, j)
Selection.SetRange Start:=l, End:=j
End Function
|
评分
-
1
查看全部评分
-
|