Search code examples
vbaoutlookoutlook-2016

Automatically Mark email in Deleted Items as Read Outlook 2016 VBA


I had a little macro set up with Outlook on another machine but now that I've switched computers I can't get it to work. When I try to run the last Private Sub, it doesn't recognize the name and pulls up the Macro selection box with no options listed.

I dislike having to manually mark emails in the Deleted Items folder as read, especially considering they had the amazing foresight to mark discarded drafts as unread.

Here's the code that used to work:

Dim WithEvents g_OlkFolder As Outlook.Items

Private Sub Application_Quit()
    Set g_OlkFolder = Nothing
End Sub

Private Sub Application_Startup()
    Set g_OlkFolder = Session.GetDefaultFolder(olFolderDeletedItems).Items
End Sub

Private Sub g_OlkFolder_ItemAdd(ByVal Item As Object)
    Item.UnRead = False
    Item.Save
End Sub

Solution

  • Upon completely throwing away my code and starting from scratch I figured out a much simpler solution than what I was trying. Thanks for all the help anyways guys!

    Sub MDAU()
    Dim DI As Outlook.Items
    Dim MSG As Object
    Set DI = Session.GetDefaultFolder(olFolderDeletedItems).Items
    Set MSG = Application.CreateItem(olMailItem)
    For Each MSG In DI
    MSG.UnRead = False
    Next
    End Sub