Remove duplicate text lines in a Word doc

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Hi, Lili. I do lots and lots of cleaning up and converting of data. I'm
fairly good with both Word and Excel, so I tend to copy and paste back and
forth a lot. If this were me, I'd be trying to convert this to a Word table
(if it's not already) and then you can paste right into Excel. Removing
dupes in Excel is much more simple. See:
http://www.officearticles.com/excel/dealing_with_duplicate_records_in_microsoft_excel.htm
Before you convert to a table, you'll want to make sure that each individual
"record" has a paragraph return at the end (not a line break).
************
Anne Troy
www.OfficeArticles.com
 
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
 
Anne,
Thank you so much-- I will convert to a table and also try what the other
user suggested and see which works fastest :^) It will be a learning
experience either way.
Thanks so much.
 
Hello Graham
Thanks so much-- will try - I may have an older version of Word because I
don't have the exact Find & Replace options that you have in your tutorial.
I'll try it at home with Windows XP pro, in case that is the same as the one
in your tutorial.
What a great resource this is!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top