Reputation: 691
I am building a code that does a search in a Outlook folder and put the body of the items together in just one item (to build a history for that case).
I am performing the search using the Find method (not sure if all correct). Once I get the search results, I'll put them in an array.
Is there a way to sort the array by date? I keep getting an error with code below:
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFldr As Outlook.MAPIFolder
Dim olItms As Outlook.Items
Dim olMail As Variant
Dim MyArray() As String
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace(”MAPI”)
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
Set olMail = myTasks.Find("[Subject] = ""*140115LS*""")
If Not (olMail Is Nothing) Then
MyArray = olMail.Display
Upvotes: 0
Views: 2518
Reputation: 66286
Call olItms.Sort("[ReceivedTime]")
before calling Find. You will also need to call FindNext in a loop until it returns null.
Upvotes: 0
Reputation: 166765
'...
Dim sFilter as string
sFilter = "@SQL=""urn:schemas:mailheader:subject"" like '%140115LS%' "
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
Set olMail = olItms.Find(sFilter)
Do While Not olMail Is Nothing
'add to array...
Set olMail = olItms.FindNext
Loop
'...
Upvotes: 2