Thread: [Solved] find and delete duplicates
View Single Post
 
Old 05-15-2013, 02:41 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following should be even faster, and won't trip up on any empty paragraphs left behind by your '^p^p' Find/Replace (eg if there were two consecutive empty paragraphs)
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, StrFnd As String, Rng As Range
With ActiveDocument
  With .Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[^13]{2,}"
    .Replacement.Text = "^p"
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchAllWordForms = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  While .Characters.Last.Previous.Text = vbCr
    .Characters.Last.Previous.Text = vbNullString
  Wend
  Set Rng = .Range
  For i = .Paragraphs.Count To 2 Step -1
    With .Paragraphs(i).Range
      StrFnd = .Text
      Rng.End = .Start
    End With
    With Rng.Find
      .Text = StrFnd
      .Replacement.Text = ""
      .MatchWildcards = False
      .Wrap = wdFindStop
      .Execute Replace:=wdReplaceAll
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote