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.
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)
领英推荐
For Microsoft Office versions From and above Office 2016 :
To do the same, we use a VBA (Microsoft Visual Basic for Applications window) code.
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
Originally published at https://www.biolit.in on January 22, 2021 by Ambu Vijayan.
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.
Professor of Medical Pharmacology, College of Medicine, University of Arizona
1 年I get a compile error, Expected: identifier...still trying.