SN,
For assistance running the macro, see:
http://www.gmayor.com/installing_macro.htm
AFAIK, the is no straightforward way to delete duplicate words in a
document. Part of the problem is how Word defines a word. In this simple
example there are four words:
one two three. They are "one " "two " "three" and "."
In this example three are seven words:
one two three one two three. They are "one " two " three " one " two "
"three" and "."
At first glance it would appear the words one two and three are duplicated.
One and two are, but on closer observation you will see that "three " is in
fact not the same as "three"
If I ran this procedure on the second example:
Sub ScratchMacroII()
Dim oWord As Range
Dim myCol As New Collection
For Each oWord In ActiveDocument.Range.Words
On Error Resume Next
myCol.Add oWord.Text, oWord.Text
If Err.Number = 457 Then oWord.Delete
Next
End Sub
I would be left with "one two three three."
I can fix that by trimming the trailing space from the word range:
Sub ScratchMacroII()
Dim oWord As Range
Dim myCol As New Collection
For Each oWord In ActiveDocument.Range.Words
On Error Resume Next
myCol.Add Trim(oWord.Text), Trim(oWord.Text)
If Err.Number = 457 Then oWord.Delete
Next
End Sub
Which leaves "one two three."
But if I run code like that on a group of e-mail addresses that contain the
punctuation "." things get fouled up real quick.
When you type an email address in a Word document Word by default will
convert that text to a hyperlink. E.g., if I type (e-mail address removed) Word
automatically changes that to a hyperlink field: { Hyperlink
"mailto:
[email protected]" }
You can see this by right clicking and e-mail address and selecting toggle
field codes.
The procedure that I sent to you searches a document for the first e-mail
address. It then compares the field code in that field to the field code in
every other field in the main text part of the document. If they match the
duplicate fields are deleted. The procedure then looks for the next e-mail
address and repeats the procedure and on and on till all duplicates are
deleted.