Find And Highlight Duplicate Paragraphs In Research Article or Thesis

Find And Highlight Duplicate Paragraphs In Research Article or Thesis

Suppose you have a large research article or thesis in Word document format which may have hundreds of pages. As part of the editing, you want to check if there are duplicate paragraphs and then highlight them to make them outstanding, so that you can deal with the duplicate sentences.

The article is separated into two versions, one for the office version before 2016 and another for versions since 2016. Kindly use codes and steps accordingly.

For Microsoft Office versions below Office 2016 :

To do the same, we use a VBA (Microsoft Visual Basic for Applications window) code.

  • For activating VBA code in Microsoft word. Open your desired word file and press Alt+F11 in your keyboard. Thus will open the VBA window.
  • Click Insert > Module. This will open another window.
  • Copy and paste below code into the opened blank module

Sub HighlightDuplicateParagraphs(
	    Dim i As Integer, j As Integer
	    Dim Original As Paragraph, Duplicate As Paragraph
	    Dim OriginalText As String, DuplicateText As String
	    
	    For i = 1 To ActiveDocument.Paragraphs.Count - 1
	        Set Original = ActiveDocument.Paragraphs(i)
	        OriginalText = Trim(Original.Range.Text)
	        If Len(OriginalText) > 0 Then
	            For j = i + 1 To ActiveDocument.Paragraphs.Count
	                Set Duplicate = ActiveDocument.Paragraphs(j)
	                DuplicateText = Trim(Duplicate.Range.Text)
	                If Len(DuplicateText) > 0 And OriginalText = DuplicateText Then
	                    Original.Range.HighlightColorIndex = wdGreen
	                    Duplicate.Range.HighlightColorIndex = wdYellow
	                    Exit For
	                End If
	            Next j
	        End If
	    Next i
	End Sub)        

  • Now, 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.


For Microsoft Office versions From and above Office 2016 :

To do the same, we use a VBA (Microsoft Visual Basic for Applications window) code.

  • To activate the VBA code in Microsoft Word. Open a blank Word file and press Alt+F11 on your keyboard. This will open the VBA window.
  • Click Tools> Macros. This will open another window.
  • Type the Macro name as "HighlightDuplicateParagraphs" and click Create. This will open an editor.

  • Copy and paste the below code into the opened module replacing everything in it.

Sub HighlightDuplicateParagraphs()
    Dim i As Integer, j As Integer
    Dim Original As Paragraph, duplicate As Paragraph
    Dim OriginalText As String, DuplicateText As String

    For i = 1 To ActiveDocument.Paragraphs.Count - 1
        Set Original = ActiveDocument.Paragraphs(i)
        OriginalText = Trim(Original.Range.Text)
        If Len(OriginalText) > 0 Then
            For j = i + 1 To ActiveDocument.Paragraphs.Count
                Set duplicate = ActiveDocument.Paragraphs(j)
                DuplicateText = Trim(duplicate.Range.Text)
                If Len(DuplicateText) > 0 And OriginalText = DuplicateText Then
                    Original.Range.HighlightColorIndex = wdGreen
                    duplicate.Range.HighlightColorIndex = wdYellow
                    Exit For
                End If
            Next j
        End If
    Next i
End Sub        

  • Now, press F5 key to run this code.
  • Now paste the text that you want to check in the blank document created earlier.
  • Press Alt + F8 to open the "Macro" dialog.
  • Select "HighlightDuplicateParagraphs" from the list of macros.
  • Click the "Run" button to execute the macro.
  • Now 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.

Originally published at https://www.biolit.in on January 22, 2021 by Ambu Vijayan.

Aline Lea

Research Analyst at Canada Revenue Agency - Agence du revenu du Canada

1 年

I can't get this to work. Once I press F5, A separate window for Macros appears. "Run" in this window is grayed out.

Jennifer Schnellmann

Professor of Medical Pharmacology, College of Medicine, University of Arizona

1 年

I get a compile error, Expected: identifier...still trying.

要查看或添加评论,请登录

Ambu Vijayan的更多文章

社区洞察

其他会员也浏览了