WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Sort Email by Received Time


;Example of how to process Outlook mail items, either sorted or unsorted
;
objOlApp = CreateObject("Outlook.Application")
objNameSpace = objOlApp.GetNamespace("MAPI")
; Get Handle to Inbox
objFolder = objNameSpace.Folders("Personal Folders")
objSubFolder = objFolder.Folders("Inbox") 
; Get MailItems Collection from Inbox 
objItems = objSubFolder.Items

; Grab UNSORTED list of email subjects and display            
data = ""
ForEach objItem in objItems
    data = StrCat(data, objItem.Subject,@crlf)
Next objItem
Message("No Sort",data)


; DESCENDING SORT - (based on 'Received Time')  
; displays list of email subjects       
data = ""
objItems.Sort("[ReceivedTime]", @True) ;descending order   
ForEach objItem in objItems
    data = StrCat(data, objItem.Subject,@crlf)
Next objItem
Message("Descending Sort  - Use this for Newest email first",data)

; ASCENDING SORT - (based on 'Received Time')  
; displays list of email subjects                 
data = ""
objItems.Sort("[ReceivedTime]", @False) ;ascending order
ForEach objItem in objItems
    data = StrCat(data, objItem.Subject,@crlf)
Next objItem
Message("Ascending Sort - Use this for Oldest first",data)


objSubFolder = 0    
objNameSpace = 0
objOlApp = 0
exit

Article ID:   W17134
File Created: 2007:07:03:14:28:26
Last Updated: 2007:07:03:14:28:26