Sorting mails by domain name?

Sorting mails by domain name?

Post by Uzmi Novce » Fri, 11 Mar 2005 20:28:51


Is there a option to sort mail adresses by server?

For example:

XXXX@XXXXX.COM
XXXX@XXXXX.COM
XXXX@XXXXX.COM

to be sorted as:

XXXX@XXXXX.COM
XXXX@XXXXX.COM
XXXX@XXXXX.COM

instead as:

XXXX@XXXXX.COM
XXXX@XXXXX.COM
XXXX@XXXXX.COM

If that can't be dome in word does anyone knows other way to solve it?

Thanks!
 
 
 

Sorting mails by domain name?

Post by Lee Hanke » Thu, 17 Mar 2005 02:16:47


Here is a Word macro that will take a document containing a plain text
list of email addresses and create a new document with those addresses
sorted by domain.

Sub sort_emails()

Dim emails(1000) As String
Dim hosts(1000) As String

Dim part As String, email As String
Dim n As Integer, isuser As Boolean

email = ""
part = ""
n = 0
isuser = True
For Each x In ActiveDocument.words
If x = "@" And isuser Then
isuser = False
part = ""
End If
If x = Chr(13) Then
If email <> "" Then
emails(n) = email
hosts(n) = part
n = n + 1
End If
email = ""
part = ""
isuser = True
Else
email = email + x
If x <> "@" Then part = part + x
End If
Next

'bubble sort
sorted = False
Do
sorted = True
For i = 0 To n - 2
If hosts(i) > hosts(i + 1) Then
sorted = False
temphost = hosts(i)
tempemail = emails(i)
hosts(i) = hosts(i + 1)
emails(i) = emails(i + 1)
hosts(i + 1) = temphost
emails(i + 1) = tempemail
End If
Next i

Loop While Not sorted

Documents.Add Visible:=True

emaillist = ""
For i = 0 To n - 1
emaillist = emaillist + emails(i) + Chr$(13)
Next i
ActiveDocument.Range.InsertAfter emaillist

End Sub


--
Posted via Mailgate.ORG Server - http://www.yqcomputer.com/

 
 
 

Sorting mails by domain name?

Post by Dian » Sat, 19 Mar 2005 11:40:13

That's neat, if you're a macro person ...

Seeing as I'm not, the way I would do it is copy and paste the
addresses into MS Excel, twice - next to each other. Select the second
column containg your addresses then set up text to columns on that
separating on the "@", select all the columns and sort on the domain
name part .....
Having the address list pasted into two columns is just to make life
easy so that you can copy paste the entire address list back out
without having to reinsert the @ symbols, and then chuck away the split
up address list.