|
非常简单!代码如下:
Sub 快速标记完全重复的句子()
Dim i As Paragraph, oSen As Range, MySearchRange As Range
Dim MyArray() As String, aArray As Variant
Application.ScreenUpdating = False
On Error Resume Next ' 忽略错误
With ActiveDocument ' 遍历段落 注:原始文献资料中提供的是ThisDocument,改为ActiveDocument
For Each i In .Paragraphs ' 如果为空白段落则跳过或者到达最后一个段落则进入下一个循环
If VBA.Len(i.Range) = 1 Or i.Range.Start = .Content.Paragraphs.Last.Range.Start Then GoTo GN
Set MySearchRange = .Range(i.Range.End, .Content.End)
MySearchRange.Select '-----------------
With Selection.Find ' 在指定的RANGE 中查找
s = i.Range
s = Replace(s, "。", ",")
s = Replace(s, ";", ",")
MyArray = VBA.Split(s, ",") ' 由逗号为分隔符(本来在句子中循环,修改)
.ClearFormatting ' 清除查找格式
For Each aArray In MyArray ' 在"句子" 中循环,如果查找到该内容,则设置为红色
Do While .Execute(findtext:=aArray)
.Parent.Font.Color = vbRed ' 将找到的句子标红
' MySearchRange.Paragraphs(1).Range.Font.Color = wdColorRed ' 整段标红
Loop
MySearchRange.Select
Next
End With
GN: Next
End With
MsgBox "OK!!!"
Application.ScreenUpdating = True
End Sub
如果你一开始就提供附件,问题早就解决了。 |
评分
-
1
查看全部评分
-
|