Sorting MAPIFolder messages by SentOn?

  • Thread starter Thread starter Scott Corrigall
  • Start date Start date
S

Scott Corrigall

I've written a macro that prints all email in a chosen folder to a
single word document but it always prints it sorted by the message's
subject. Is it possible to sort it by the SentOn field in the messages? I
tried this:

SourceFolder.Items.Sort "SentOn", False

but it doesn't work. SourceFolder (an Outlook.MAPIFolder) and its items are
all accessible and work fine. It's only the sort that fails.

Can I sort by the SentOn field?

Scott
 
Make sure you sort and access the same instance of of the Items object -
each time you call MAPIFolder.Items, Outlook returns a brand new object; you
need to cache Items and work with that instance only. Change your code as
follows:

set Items = SourceFolder.Items
Items.Sort "[SentOn]", False
for i = 1 to Items.Count
....

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top