Might I suggest you get a grip on your inbox! 10,000 items!?!
Seriously, though, the trouble is that, although new emails end up at the "top" of the email list, they aren't stored in strict date order (at least on my machine they aren't), so it's not as simple as quitting the loop once a certain date (e.g. today minus x-days) has been reached.
One way around it would be to set up a filter in Outlook so your target emails end up in one folder and run the search on that. That would also fix the "Report Items" issue which don't have the elements you're looking for.
In this bit of code Folders(1) is the mailbox (assuming you have only one account configured it'll be "1"). The Folders("Inbox") is then self explanatory.
So... if you create a Trade Notifications folder it would read
Or as a subfolder of the Inbox:
This would speed things up dramatically and you'd have the added benefit of an organised Inbox.
Also, try changing targetemail.SentOn to targetemail.ReceivedTime... Report items might not have a "SentOn" time, but if the do have a "ReceivedTime" it might fix that issue. It's only a guess, because I don't have any reports to look at.
I'm not overly familiar with Outlook, so I'm not very sure on this one.
Tim
Bookmarks