M
MikeE
I want to sort my Outlook Contacts list so I can insert the address, name,
ect into a Word 2003 template using a list box. Presently I am sorting the
600 plus addresses as follows:
Private Sub UserForm_Activate()
Dim objOutlook As Outlook.Application
Dim fdrContacts As Outlook.MAPIFolder
Dim itmContacts As Outlook.ContactItem
Dim k As Integer
Dim j As Integer
Dim i As Integer
Dim aBuf As String
Set objOutlook = New Outlook.Application
Set fdrContacts = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
For Each itmContacts In fdrContacts.Items
lstCompanyList.AddItem itmContacts.ItemProperties(52).Value _
& " " & itmContacts.ItemProperties(26)
Next
With lstCompanyList
k = .ListCount
For j = 0 To k - 1
For i = (j + 1) To (k - 1)
If .List(i) < .List(j) Then
aBuf = .List(j)
.List(j) = .List(i)
.List(i) = aBuf
End If
Next i
Next j
End With
End Sub
The problem is that it takes forever for the list box to be populated with
the names of the companies. When you open up the outlook contacts it opens
up immediatly and is sorted. How can I get a word VBA macro to open and sort
the list box as fast as the outlook contacts.
The other problem I have is that all of the names are sorted capitals first
then all the lower case names.
There has to be a better way. Any ideas?
Thanks Mike
ect into a Word 2003 template using a list box. Presently I am sorting the
600 plus addresses as follows:
Private Sub UserForm_Activate()
Dim objOutlook As Outlook.Application
Dim fdrContacts As Outlook.MAPIFolder
Dim itmContacts As Outlook.ContactItem
Dim k As Integer
Dim j As Integer
Dim i As Integer
Dim aBuf As String
Set objOutlook = New Outlook.Application
Set fdrContacts = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
For Each itmContacts In fdrContacts.Items
lstCompanyList.AddItem itmContacts.ItemProperties(52).Value _
& " " & itmContacts.ItemProperties(26)
Next
With lstCompanyList
k = .ListCount
For j = 0 To k - 1
For i = (j + 1) To (k - 1)
If .List(i) < .List(j) Then
aBuf = .List(j)
.List(j) = .List(i)
.List(i) = aBuf
End If
Next i
Next j
End With
End Sub
The problem is that it takes forever for the list box to be populated with
the names of the companies. When you open up the outlook contacts it opens
up immediatly and is sorted. How can I get a word VBA macro to open and sort
the list box as fast as the outlook contacts.
The other problem I have is that all of the names are sorted capitals first
then all the lower case names.
There has to be a better way. Any ideas?
Thanks Mike