View Single Post
  #13   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default How do I delete duplicate entries in a Word document?

SN,

If you email addresses are in fact hyperlinks then this method posted by
friend and fellow MVP Helmut Weber in the VBA groups might be better:

Sub Test0083456()
Dim Linka As Hyperlink
Dim Linkb As Hyperlink
For Each Linka In ActiveDocument.Hyperlinks
For Each Linkb In ActiveDocument.Hyperlinks
If Linka.Address = Linkb.Address Then
If Linka.Range.start Linkb.Range.start Then
Linkb.Range.Delete
End If
End If
Next
Next
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


SN wrote:
Dear Greg,
Thanks vm .... but this appears too technical to me.... I am just an
average computer user and cannot really understand what you say.....
Isnt there any straightforward way to 'DELETE DUPLICATE WORDS IN A
DOCUMENT?"
Rgds/SN

"Greg Maxey" wrote:

Provided the email entries are of the ????????@??????.??? format
(where ? is any character) then this might work:

Sub ScratchMacro()
Dim pStr As String
Dim oRng As Range
Dim i As Long
Dim j As Long
Dim oFld As Field
Dim bLoop As Boolean
i = 1
bLoop = True
Do
Set oRng = ActiveDocument.Range
oRng.Start = i
With oRng.Find
.Text = "?{1,}\@?{1,}.?{3}"
.MatchWildcards = True
Do
.Execute
If Not .Found Then
bLoop = False
Exit Do
End If
If oRng.Start = i Then
pStr = Trim(oRng.Text)
i = oRng.End
j = 0
For Each oFld In ActiveDocument.Fields
If InStr(oFld.Code, pStr) 0 Then
j = j + 1
If j 1 Then
oFld.Delete
End If
End If
Next oFld
Exit Do
Else
oRng.Collapse wdCollapseEnd
End If
Loop While .Found = True
End With
Loop While bLoop = True
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


SN wrote:
Helo, I am facing exactly the same problem. Did you find the
answer?? I will very much appreciate if you can share it with me.
Thank you very much
SN

"ayesha" wrote:

I have a large word document with lots of email addresses, many of
which are duplicate entries- how do I delete these repeat entries
without having to rely on the ControlF function?