How to Find & Highlight Duplicate Sentences in MS Word

Published by Get eSolutions on

Sometimes we need to check, is there any duplicate paragraph or repeat sentences in our MS-Word document. If we start finding the duplicacy & removing them manually, which takes a lot of time. Because we could have a long document which may consume our time and efforts. But unfortunately, MS-Word doesn’t have this important feature to find duplicate phrases.

In this video, you will know the solutions to find & highlight duplicate sentences in Microsoft Word 2007, 2010, 2013, 2019 & so on. You just need to use VBA Macro code, which you will find below.

getesolutionsMACRO CODE
Sub FindDuplicateParas()
 Application.ScreenUpdating = False
 Dim i As Long, RngSrc As Range, RngFnd As Range
 Const Clr As Long = wdBrightGreen
 Dim eTime As Single
 eTime = Timer
 Options.DefaultHighlightColorIndex = Clr
 With ActiveDocument
   With .Range.Find
     .Forward = True
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
   End With
   For i = 1 To .Paragraphs.Count
     If i Mod 100 = 0 Then DoEvents
     On Error Resume Next
     Set RngSrc = .Paragraphs(i).Range
     If RngSrc.HighlightColorIndex <> Clr Then
       Set RngFnd = .Range(.Paragraphs(i).Range.End, .Range.End)
       If Len(RngSrc.Text) < 256 Then
         With RngFnd.Find
           .Text = RngSrc.Text
           .Replacement.Text = "^&"
           .Replacement.Highlight = True
           .Wrap = wdFindStop
           .Execute Replace:=wdReplaceAll
         End With
         With RngFnd
           With .Find
             .Text = Left(RngSrc.Text, 255)
             .Wrap = wdFindStop
           End With
           Do While .Find.Found
             If RngSrc.Text = .Duplicate.Text Then
               RngSrc.HighlightColorIndex = Clr
               .Duplicate.HighlightColorIndex = Clr
             End If
             .Collapse wdCollapseEnd
         End With
       End If
     End If
 End With
 ' Report time taken. Elapsed time calculation allows for execution to extend past midnight.
 MsgBox "Finished. Elapsed time: " & (Timer - eTime + 86400) Mod 86400 & " seconds."
 Application.ScreenUpdating = True
 End Sub

1 Comment

Cee Em · February 4, 2021 at 4:19 pm

Thank you for this great script. I have just been introduced to macros and they make life so much easier.

Leave a Reply