Skip to main content

How to find and highlight duplicate paragraphs in Word document?

Author: Xiaoyang Last Modified: 2024-07-31

Supposing, you have a large Word document which may have hundreds of pages, now, you want to check if there are duplicate paragraphs and then highlight to make them outstanding, so that you can deal with the duplicate sentences. How could you find and highlight the duplicate paragraphs quickly and easily in Word document?

Find and highlight the duplicate paragraphs in Word document with VBA code


Find and highlight the duplicate paragraphs in Word document with VBA code

To find and highlight the duplicate paragraphs in a Word document, the following VBA code can do you a favor, please do as this:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. And then, click Insert > Module, copy and paste below code into the opened blank module:

VBA code: Find and highlight the duplicate paragraphs in Word document:

Sub highlightdup()
    Dim I, J As Long
    Dim xRngFind, xRng As Range
    Dim xStrFind, xStr As String
    Options.DefaultHighlightColorIndex = wdYellow
    Application.ScreenUpdating = False
    With ActiveDocument
        For I = 1 To .Paragraphs.Count - 1
            Set xRngFind = .Paragraphs(I).Range
            If xRngFind.HighlightColorIndex <> wdYellow Then
                For J = I + 1 To .Paragraphs.Count
                    Set xRng = .Paragraphs(J).Range
                    If xRngFind.Text = xRng.Text Then
                        xRngFind.HighlightColorIndex = wdBrightGreen
                        xRng.HighlightColorIndex = wdYellow
                    End If
                Next
            End If
        Next
    End With
End Sub

3. And then press F5 key to run this code, all the duplicate sentences are highlighted at once, the first displayed duplicate paragraphs are highlighted with green color, and other duplicates are highlighted with yellow color, see screenshot:

All duplicate sentences highlighted with the first displayed duplicate paragraphs highlighted in green and other duplicates in yellow

Best Office Productivity Tools

Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!

๐Ÿค– Kutools AI Features: AI Assistant / Real-Time Assistant / Super Polish (Preserve Format) / Super Translate (Preserve Format) / AI Redaction / AI Proofread...

๐Ÿ“˜ Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF...

โœ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...

๐Ÿงน Effortless Clean: Sweap away Extra Spaces / Section Breaks / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...

โž• Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Multiple Pictures / Discover more in the Insert group...

๐Ÿ” Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...

โญ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...

๐ŸŒ Supports 40+ Languages: Use Kutools in your preferred language โ€“ supports English, Spanish, German, French, Chinese, and 40+ others!

Kutools and Kutools Plus tabs on the Word Ribbon
๐Ÿ‘‰ Want to try these features? Download Kutools for Word now! ๐Ÿš€
 

Best Office Productivity Tools

Kutools for Word - 100+ Tools for Word