Outlook 2010, copy an email into folder and mark copied email as read but keep original email as unread

StackOverflow https://stackoverflow.com/questions/23572899

  •  19-07-2023
  •  | 
  •  

Question

I have rules set up to copy emails containing certain keywords to specific folders and mark as read.

The problem i'm having is when it copies those emails to the folders it marks the original email in the inbox as read, and which can cause me to miss the message. If i don't mark it as read then when i read it in the Inbox it stays unread in the specific folder.

I cant find any rule properties to accomplish this, anyone have any ideas?

Was it helpful?

Solution

Set the rules to copy to the target folders but not mark as read.

Put this untested code in the ThisOutlookSession module. Assumes the target folders are directly under the Inbox. If buried deeper, add .Folders as necessary.

Option Explicit

' one line for each target folder
Private WithEvents myOlItemsA  As Outlook.Items
Private WithEvents myOlItemsB  As Outlook.Items

Private Sub Application_Startup()

    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")

    ' one line for each target folder
    Set myOlItemsA = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameA").Items
    Set myOlItemsB = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameB").Items

End Sub

' one copy of ItemAdd code for each target folder
Private Sub myOlItemsA_ItemAdd(ByVal item As Object)

    On Error GoTo ErrorHandler
    Dim Msg As Outlook.MailItem

    If TypeName(item) = "MailItem" Then
        Set Msg = item
        Msg.Unread = False
    End If

ProgramExit:
    Set Msg = Nothing
    Exit Sub

ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Resume ProgramExit

End Sub

Private Sub myOlItemsB_ItemAdd(ByVal item As Object)
 ' same code as for myOlItemsA
End Sub

Code based on this post Using VBA to read new Outlook Email?

The rules move mail to target folders. The ItemAdd code acts on the items added to the target folders.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top