I wrote the below in an attempt to save emails older than six months in an external folder:
Option Explicit
Public Sub EBS()
Dim oMail As MailItem
Dim sPath As
Instead of iterating over all items in the folder and checking the following condition:
If oMail.ReceivedTime < DateAdd("d", -180, Now) Then
You can find the required items and iterate over a subset of items that correspond to your conditions.
See How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET) for a sample code. There you can find a similar article related to the Restrict method (can't post more than one link).
You would also want to use Items.Find/FindNext or Items.Restrict instead of looping through all items in a folder.
UPDATE:
setItems = oInboxFolder.Items
set RestrictedItems = setItems.Restrict(" ([ReceivedTime ] < '05/02/2014')) AND ([MessageClass] = 'IPM.Note' ")
for I = RestrictedItems.Count to 1 step -1 do
Set oMail = RestrictedItems.Item(I)
next
When you delete (or move) item 1, item 2 moves into position 1. You skip that item and move on to item 3 which is now in position 2. For Each works the same way.
One way of dealing with this is For i = oInboxFolder.Items.Count to 1 step -1