14

Outlook 2010. Want to create a rule that moves all mail from my inbox to another folder:

  • Has been read
  • Is older than X days

I was looking at Auto-archiving, but it does not seem to let me be this specific with my criteria.

1
  • Could someone forward this to Microsoft Outlook team?
    – Jayan
    Mar 16 '17 at 6:18
8

The best way I've found to do this at the moment is to create a new Search Folder with custom criteria e.g with items modified on or before a certain date. I then right-click the folder and choose 'Delete All' which sends all items in the Search Folder to the bin.

1
  • This is not an answer, because the messages are not moved to a folder, they are only moved to the bin.
    – Pro Backup
    Dec 3 '16 at 12:22
5

The search folders are the answer, however the OP asked about mail older than a particular date. If you use "modified last week" then it shows everything within the last week and filters out things older than 1 week. For the inverse that, use language like:

  • 8 days ago
  • 1 week ago
  • etc...

enter image description here

1
  • Great, did not know that you can write natural language for the value!
    – RipperDoc
    Aug 7 '14 at 5:39
4

I had been looking for something similar. I have to use a macro as auto-archive is disabled for my installation. Here's what I came up with:

Option Explicit
Private Sub Application_MAPILogonComplete()
    ' this runs on app startup
    Const MSG_AGE_IN_DAYS = 7

    Dim oFolder As Folder
    Dim oFilteredItems As Outlook.Items
    Dim oItem As MailItem
    Dim oDate As Date

    oDate = DateAdd("d", -MSG_AGE_IN_DAYS, Now())
    oDate = Format(oDate, "mm/dd/yyyy")

    ' you can use this command to select a folder
    'Set oFolder = Application.Session.PickFolder

    Set oFolder = Me.Session.Folders.GetFirst

    ' shows all the folder names
    'For Each fldr In oFolder.Folders
    '    Debug.Print fldr.Name
    'Next fldr

    ' this was the sub-folder I wanted to cleanup.
    Set oFolder = oFolder.Folders("Storage").Folders("batch runs")

    Debug.Print "checking " & oFolder.FolderPath
    Debug.Print "for msgs older than " & oDate

    ' you can modify the filter to suit your needs
    Set oFilteredItems = oFolder.Items.Restrict("[Received] <= '" & oDate & "' And [Unread] = True")

    Debug.Print "removing " & oFilteredItems.Count & " items"

    While oFilteredItems.Count > 0
        Set oItem = oFilteredItems.GetFirst
        Debug.Print "   " & oItem.UnRead & " " & oItem.Subject

        ' the remove method permanently deletes the item.
        oFilteredItems.Remove 1
        'Debug.Print oFilteredItems.Count & " items left"
    Wend

    Debug.Print ". end"

    Set oFolder = Nothing
    Set oFilteredItems = Nothing
    Set oItem = Nothing
End Sub

This macro is attached to the last phase of the application's lifecycle; it runs when Outlook starts up. You'll probably also want to sign it (and trust your signature) so you do get security complaints.

HTH

1

For the upcoming researchers, i have done the following using Developer tools

    Public WithEvents olItems As Outlook.Items

    Sub Application_Startup()
        Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
    End Sub

    Private Sub olItems_ItemChange(ByVal Item As Object)
        Dim deFolder As Folder
     
        'Ensure the email marked as read
        If TypeOf Item Is MailItem And Item.UnRead = False Then
     
        'Check the email subject and then move to specific folder
        'You can change these conditions and folders as per your needs
        If InStr(LCase(Item.Subject), "test") > 0 Then
           Set deFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Test")
           Item.Move deFolder
        End If
     
        If InStr(LCase(Item.Subject), "worklog") > 0 Then
           Set deFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("WorkLog")
           Item.Move deFolder
        End If
     
        If InStr(LCase(Item.Subject), "report") > 0 Then
           Set deFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Report")
           Item.Move deFolder
        End If
    End Sub

After that, you should digitally sign this code. Use the built-in “Digital Certificates for VBA Projects” tool to create a new certificate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.