title: VBA code to delete emails after x Days
body: <p>I am trying to delete all emails in my inbox that are older than 90 days. I am not able to use the auto archive since it has been disabled at my office. I have some code that does not seem to be deleting every mail that is older than 90 days. I think the issue might be with my loop. I am using Outlook 2010 with exchange 2010.</p>
  
  <pre><code>Private Sub RemoveEmail90()
  
  Dim olSession As Outlook.Application, olNamespace As NameSpace
  Dim olInbox As Outlook.MAPIFolder
  Dim i As Integer
  Set olSession = New Outlook.Application
  Set olNamespace = olSession.GetNamespace("MAPI")
  Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
  Set Delete_Items = olInbox.Items
  
  For i = Delete_Items.Count To 1 Step -1
      If TypeName(Delete_Items.Item(i)) = "MailItem" Then
              If DateDiff("d",now, Delete_Items.Item(i).ReceivedTime) &gt; 90 Then Delete_Items.Item(i).Delete
      End If
  Next
  
  Set olSession = Nothing
  Set olNamespace = Nothing
  Set olInbox = Nothing
  End Sub
  </code></pre>