How to: Use the Table Object to Performantly Enumerate Filtered Items in a Folder
Outlook Developer Reference
The code sample in this topic uses the Table object to enumerate a filtered set of items in the Inbox that were last modified after May 1, 2005. For each of these items, the code sample prints these values: the subject, the time that the item was last modified, and whether the item is hidden. The procedure is as follows:
The sample defines a filter based on the value of the LastModificationTime property of mail items.
It applies the filter to Folder.GetTable and obtains a Table of a subset of mail items in the Inbox that satisfies the filter.
The returned table contains a default set of properties for each of the filtered items: EntryID, Subject, CreationTime, LastModificationTime, and MessageClass.
It then uses Columns.RemoveAll and Columns.Add to update the Table with the actually desired properties: Subject, LastModificationTime, and the hidden attribute (PR_ATTR_HIDDEN). It specifies properties with their explicit built-in names if they exist (for example, Subject, LastModificationTime), and only when they don't, it references the properties by their namespaces (for example, the hidden attribute of a mail item).
The Table objects returned from Folder.GetTable in Step 2 and Columns.Add in Step 3 contain different property values but for the same set of filtered items in the Inbox.
Lastly, it uses Table.GetNextRow to enumerate the filtered items (until Table.EndOfTable becomes true), displaying the values of the three desired properties for each item.
Dim Filter As String
Dim oRow As Outlook.Row
Dim oTable As Outlook.Table
Dim oFolder As Outlook.Folder
'Get a Folder object for the Inbox
Set oFolder = Application.Session.GetDefaultFolder(olFolderInbox)
'Define Filter to obtain items last modified after May 1, 2005
Filter = "[LastModificationTime] > '5/1/2005'"
'Restrict with Filter
Set oTable = oFolder.GetTable(Filter)
'Remove all columns in the default column set
'Specify desired properties
'PR_ATTR_HIDDEN referenced by the MAPI proptag namespace
'Enumerate the table using test for EndOfTable
Do Until (oTable.EndOfTable)
Set oRow = oTable.GetNextRow()