I am trying to loop over the emails in folder, download the attachments and move the message to a folder labelled "processed." I want every email in the folder to the Processed folder and only keep the attachment from the most recent email. I figured the easiest way to do this would be to just loop through them all and have the most recent go last, overwriting the attachment each time.
Code Snippet Below
oOlInbNo.Items.Sort "[ReceivedTime]", True
Do While oOlInbNo.Items.count > 0
For Each MailItem In oOlInbNo.Items
For Each atch In MailItem.Attachments
If Right(atch.Filename, 3) = "xls" Then
atch.SaveAsFile NewFileNameNo
End If
Next atch
MailItem.Move oOlInbNo.Folders("Processed")
Next MailItem
Loop
However, when I run this it processes emails in this order
August 31 September 6 September 1 September 2
I cannot figure out why Sept 6 is going out of order.