# Removing duplicate text in a word document



## Vijay333 (Aug 6, 2008)

Hi,

Hope the topic is self-explanatory.

i.e,

In a lengthy word document, is there any short cut or simple method by which we can locate and delete duplicate text within that document?

Thanks

Vijay


----------



## macropod (Apr 11, 2008)

Hi Vijay,

What is the criterion for determining that the text is duplicate (eg: a certain number of charaters, a certain number of words, a sentence, a whole paragraph)? What about deliberate duplications (eg a heading replicated for a cross-reference or table of contents)?


----------



## Vijay333 (Aug 6, 2008)

Hi macropod,

Thanks for your fast turn-around.

My response in one word

sentences

would be mighty helpful if you can address the issue.

Thanks again

Vijay



macropod said:


> Hi Vijay,
> 
> What is the criterion for determining that the text is duplicate (eg: a certain number of charaters, a certain number of words, a sentence, a whole paragraph)? What about deliberate duplications (eg a heading replicated for a cross-reference or table of contents)?


----------



## macropod (Apr 11, 2008)

Hi Vijay,

You could use a macro like:

```
Sub KillDuplicates()
Dim TrkStatus As Boolean
Dim i As Integer
Dim STxt As String
Dim TestRng As Range
Application.ScreenUpdating = False
' Store current Track Changes status, then switch off
With ActiveDocument
  TrkStatus = .TrackRevisions
  .TrackRevisions = False
  For i = 1 To .Sentences.Count
    If i > .Sentences.Count Then Exit For
    With .Sentences(i)
      STxt = .Text
      Set TestRng = .Characters.Last
      With TestRng
        .MoveStart wdCharacter, 1
        .MoveEnd wdStory, 1
      End With
    End With
    If Not IsNumeric(STxt) Then
      With TestRng.Find
        .ClearFormatting
        .Text = STxt
        With .Replacement
          .ClearFormatting
          .Text = ""
        End With
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
      End With
    End If
  Next
' Restore original Track Changes status
  .TrackRevisions = TrkStatus
End With
Application.ScreenUpdating = True
End Sub
```
The above macro will not process any 'sentences' that consist of numbers followed by periods (eg 1. 11. etc). That's because, if the 1. occurs in the document before the 11. occurs, the Find/Replace operation will find the '1.' in 11. and replace it, leaving just a 1 (minus any trailing spaces) - in spite of the MatchWholeWord setting.


----------



## Vijay333 (Aug 6, 2008)

Hi macropod,

thanks very much for your response.

looks like you've put in quite some effort into this coding.

Appreciate and thank you for the same very much.

I'm not a techie though.

I will try and see how I can interface it with any word doc.

to locate and remove duplicates


Thanks once again

Vijay:wave:




macropod said:


> Hi Vijay,
> 
> You could use a macro like:
> 
> ...


----------

