本帖最后由 13907933959 于 2016-4-1 09:25 编辑
求前辈们帮忙!谢谢! 请查看下面的模拟附件!
今天在网上找到一个不知是那位前辈编写的代码,能运行,可不知为什么却不能找到重复的句子,也未对其标为红色。
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
|