View Single Post
  #4   Report Post  
macropod
 
Posts: n/a
Default Remove duplicate text lines in a Word doc

Hi Lili,

If the duplicate lines you're referring to are actually separate paragraphs,
the following code should clean the document up nicely:

Option Explicit
Dim SBar As Boolean ' Status Bar flag
Dim TrkStatus As Boolean ' Track Changes flag

Private Sub MacroEntry()
' Store current Status Bar status, then switch on
SBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
' Store current Track Changes status, then switch off
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
End With
' Turn Off Screen Updating
Application.ScreenUpdating = False
End Sub

Private Sub MacroExit()
' Clear the Status Bar
Application.StatusBar = False
' Restore original Status Bar status
Application.DisplayStatusBar = SBar
' Restore original Track Changes status
ActiveDocument.TrackRevisions = TrkStatus
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

Sub KillDuplicateParas()
Call MacroEntry
Dim i As Long, j As Long
Dim eTime As Single
eTime = Timer
With ActiveDocument
If .Paragraphs.Count 1 Then
' Loop backwards to preserve paragraph count & indexing.
' Start at 2nd-last paragraph.
For i = .Paragraphs.Count - 1 To 1 Step -1
' Ignore empty paragraphs
If Len(.Paragraphs(i).Range.Text) 1 Then
' Loop backwards to preserve paragraph count & indexing.
' Stop atlast preceding paragraph.
For j = .Paragraphs.Count To i + 1 Step -1
' Report progress on Status Bar.
Application.StatusBar = i & " paragraphs to check. "
' No point in checking paragraphs of unequal length.
If Len(.Paragraphs(i).Range) = Len(.Paragraphs(j).Range)
Then
' Test strings of paragraphs of equal length.
If .Paragraphs(i).Range = .Paragraphs(j).Range Then
' Delete duplicate paragraph.
.Paragraphs(j).Range.Delete
' or colour text of duplicate paragraph.
'.Paragraphs(j).Range.Font.Color = wdColorRed
End If
End If
Next
End If
Next
End If
End With
' Report time taken. Elapsed time calculation allows for execution to extend
past midnight.
MsgBox "Finished. Elapsed time: " & (Timer - eTime + 86400) Mod 86400 & "
seconds."
Call MacroExit
End Sub

Cheers


"Lili Vivanco" Lili wrote in message
...
We printed all the records in our database for QA/QC before dumping them

into a
new database.
I used Word to remove extra line breaks and that worked very well. But I
noticed that some text lines (of the title field) are duplicated in some
records-- the consequence of a previous conversion.
Is there a way I can use Word (macro, find & replace of

formatting--what??)
to remove the dupicate text lines? There are almost 8,000 pages of

printed
records and I would hate to have to find them and change them one by one.
If Word cannot do that, does anyone know what else might work?
Thank you for anything at all. Even a no will save me from hours of

reading
help columns.