Table.Sort method (Outlook)

Sorts the rows of the Table by the property specified in SortProperty and resets the current row to just before the first row in the Table.

Syntax

expression.Sort (SortProperty, Descending)

expression A variable that represents a Table object.

Parameters

Name Required/Optional Data type Description
SortProperty Required String Specifies the property to use to sort the rows of the Table.
Descending Optional Boolean Whether to sort the Table in descending order.

Remarks

SortProperty can be any explicit built-in property or custom property, with the exception of binary and multi-valued properties. The property must be referenced by its explicit string name; it cannot be referenced by namespace. For further information on specifying sort properties, see Sorting Items in a Folder.

Sorting the table is equivalent to calling a MoveToStart method. The cursor will be positioned to the start of the Table.

If Table.Sort and then Table.Restrict are called, the filtered items in the new Table will be sorted by the same SortProperty and SortOrder.

Table.Sort only supports sorting on a single column.

Example

The following code sample shows how to sort the rows in a Table based on the ReceivedTime property, and prints the value of the MAPI normalized subject property for each row in the sorted table.

Sub SortTableByReceivedTime() 
 
 Dim oT As Outlook.Table 
 
 Dim oRow As Outlook.Row 
 
 Set oT = Session.GetDefaultFolder(olFolderInbox).GetTable 
 
 'Add normalized subject (subject without RE:, FW: and other prefixes)to the column set 
 
 oT.Columns.Add ("http://schemas.microsoft.com/mapi/proptag/0x0E1D001E") 
 
 
 
 'Sort by ReceivedTime in descending order 
 
 oT.Sort "[ReceivedTime]", True 
 
 
 
 Do Until oT.EndOfTable 
 
 Set oRow = oT.GetNextRow 
 
 'Print the normalized subject of each row 
 
 Debug.Print oRow("http://schemas.microsoft.com/mapi/proptag/0x0E1D001E") 
 
 Loop 
 
End Sub

See also

Table Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.