none
Delete Old mails from current folder via VBA RRS feed

  • Question

  • Dear Expert,

    Is it possible to run a marco and clear all the mails (send to deleted items) in highlighted folder if mails are older than 2 days (today minus 2)?

    I am using windows XP and Outlook 10.

    Thanks

    Elton


    • Edited by Eltonlaw Wednesday, August 29, 2012 6:57 AM
    Wednesday, August 29, 2012 6:57 AM

Answers

  • Sub kindergarten()
    Dim d As Date
    d = Now() - 2
    Set Items = ThisOutlookSession.ActiveExplorer.CurrentFolder.Items
    Dim f As String
    f = "([ReceivedTime] <= '" & Year(d) & "-" & Month(d) & "-" & Day(d) & "')"
    Set Item = Items.Find(f)
    While Not (Item Is Nothing)
      Item.Delete
      Set Item = Items.FindNext
    Wend
    End Sub

    Friday, August 31, 2012 12:55 PM

All replies

  • sure it is. Are you asking for ready to use code snippet or hint how to do it? :D
    Wednesday, August 29, 2012 8:51 AM
  • Dear DamianD,

    Do you know how to do so?

    Actually, my Outlook VBA does not reach even kindergarten level. Maybe, pre-nursy level..

    Thanks for help.

    Elton

    Friday, August 31, 2012 7:33 AM
  • Sub kindergarten()
    Dim d As Date
    d = Now() - 2
    Set Items = ThisOutlookSession.ActiveExplorer.CurrentFolder.Items
    Dim f As String
    f = "([ReceivedTime] <= '" & Year(d) & "-" & Month(d) & "-" & Day(d) & "')"
    Set Item = Items.Find(f)
    While Not (Item Is Nothing)
      Item.Delete
      Set Item = Items.FindNext
    Wend
    End Sub

    Friday, August 31, 2012 12:55 PM