Article ID: 183053
Article Last Modified on 2/27/2004
Sub SortContacts()
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
Set MyFolder = olns.GetDefaultFolder(olFolderContacts)
' Create a collection of items
Set MyItems = MyFolder.Items
' Sort the collection
MyItems.Sort "[CompanyName]", False
' Loop through the sorted collection
For Each MyItem in MyItems
MsgBox MyItem.CompanyName
Next MyItem
End Sub
For comparative purposes, the incorrect approach provided in the Help file
is:
Sub SortContacts()
Set ol = New Outlook.Application
Set olns = ol.GetNameSpace("MAPI")
Set MyFolder = olns.GetDefaultFolder(olFolderContacts)
MyFolder.Items.Sort "[CompanyName]", False
' MyFolder.Items causes Outlook to re-fetch the collection.
For Each MyItem in MyFolder.Items
MsgBox MyItem.CompanyName
Next MyItem
End Sub
NOTE: This problem also existed in the Outlook 97 version of this Help
file.
Additional query words: OutSol OutSol98
Keywords: kbprogramming kbcode KB183053