Sort Method

Applies To

Items Collection object.

Description

Sorts the collection of items by the specified property. The index for the collection is reset to 1 upon completion of this method.

Syntax

expression.Sort(Property, Descending)

expression An expression that returns an Items object.

Property Required String. The name of the property by which to sort, enclosed in brackets (for example, "[CompanyName]"). May not be a multivalued property, such as a category.

Descending Optional Boolean. True to sort in descending order. The default value is False (ascending).

Example

The following example sorts the Items collection for the default Contacts folder by the "CompanyName" property and then displays the sorted items, each in turn.

set myFolder = _
    olNameSpace.GetDefaultFolder(olFolderContact)
myFolder.Items.Sort "[CompanyName]", False
For Each myItem in myFolder.Items
    myItem.Display
Next myItem