本帖最后由 13907933959 于 2019-7-29 07:00 编辑
师傅好! 好的、是 gbgbxgb 老师的这个代码吗?是要删除下面红色代码中的 – 1 吗?
Sub SearchDuplicateStr() Dim theStr$, d As Object, i&, j&,theStrTemp$ Dim reg As Object, theMatches As Object,theMatch As Variant ' Set d =CreateObject("Scripting.Dictionary") Set reg =CreateObject("VBScript.RegExp") With reg .Global = True .MultiLine = True .Pattern = "^[^、]+" End With With ActiveDocument .Content.Find.Execute "(重复[!^13]{1,}", , ,True, , , , , , , wdReplaceAll .Range.Font.ColorIndex = wdAuto theStr = .Range Set theMatches = reg.Execute(theStr) For Each theMatch In theMatches theStr = theMatch d(theStr) = d(theStr) + 1 Next theMatch reg.Global = False theStr = .Range For i = 0 To d.Count - 1 j = d.items()(i) If j > 1 Then theStrTemp = d.keys()(i) reg.Pattern = "^"& theStrTemp & "、" theStrTemp = theStrTemp &"、(重复"& j - 1 & "个)" theStr = reg.Replace(theStr,theStrTemp) End If Next i .Range = theStr .Range(.Range.End - 1,.Range.End).Delete For Each theMatch In .Paragraphs With theMatch theStr = .Range If InStr(1, theStr, "(") = 0 Then theStr = Replace(theStr,"、","") theStr = Left(theStr,Len(theStr) - 1) If d(theStr) > 1 Then.Range.Font.ColorIndex = wdRed End If End With Next theMatch End With Set theMatches = Nothing Set theMatch = Nothing Set d = Nothing End Sub
|