|
以下代码为寻找word文档中未知重复的代码,来源于[size=-1]王殿佑《[size=-1]Word VBA 应用程序在处理文档未知重复内容中的应用》,
Sub SearchSamesQuickly()
Dim i As Paragraph, oSen As Range, MySearchRange As Range
Dim MyArray() As String, aArray As Variant
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)
With MySearchRange.Find ' 在指定的RANGE 中查找
MyArray = VBA.Split(i.Range, ",") ' 由逗号为分隔符(本来在句子中循环,修改)
.ClearFormatting ' 清除查找格式
For Each aArray In MyArray ' 在"句子" 中循环,如果查找到该内容,则设置为红色
Do While .Execute(findtext:=aArray)
MySearchRange.Paragraphs(1).Range.Font.Color = wdColorRed ' 整段标红
Loop
Next
End With
GN: Next
End With
End Sub
问题:
MySearchRange.Paragraphs(1).Range.Font.Color = wdColorRed ' 整段标红
这句代码将含有重复文字的段落整段标红,能否修改为只标红重复的句子?
补充内容 (2013-7-31 08:52):
附件见 14楼 |
|