0
votes

I wonder if you could help me with the following problem.
I have a huge document that contains many duplicate paragraphs. I've found a macro on the Internet that can find them all and delete them:

Sub DeleteDuplicateParagraphs()
'PURPOSE: Remove Duplicate Paragraphs Throughout the Entire Word Document
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim p1 As Paragraph
Dim p2 As Paragraph
Dim DupCount As Long

DupCount = 0

For Each p1 In ActiveDocument.Paragraphs
  If p1.Range.Text <> vbCr Then 'Ignore blank paragraphs

    For Each p2 In ActiveDocument.Paragraphs
      If p1.Range.Text = p2.Range.Text Then
        DupCount = DupCount + 1
        If p1.Range.Text = p2.Range.Text And DupCount > 1 Then p2.Range.Delete
      End If
    Next p2

  End If

  'Reset Duplicate Counter
    DupCount = 0

Next p1

End Sub

However, I would like to know if there is a way to simulate Enter key press in order to create a new paragraph in the place where each duplicate was deleted. In other words, I need to replace the duplicate paragraphs with a new empty paragraph OR to delete the duplicate text without actually removing the paragraph.
I hope I was clear enough to make you see what I mean.
Thank you anyway.

1

1 Answers

0
votes

Simply change:

p2.Range.Delete

to:

p2.Range.Text = vbCr