Marco Tulio
Marco Tulio

Reputation: 3

Mark Outlook 2016 messages as read on specific folder

I have the following macro in ThisOutlookSession on Outlook 2016:

Private WithEvents g_OlkFolder As Outlook.Items
Private Sub Application_Startup()
   Set olNs = Application.GetNamespace("MAPI")
   Set g_OlkFolder = olNs.Folders.Item("[myaccount]").Folders.Item("enviadas").Items
End Sub
Private Sub g_OlkFolder_ItemAdd(ByVal Item As Object)
   Item.UnRead = False
   Item.Save
End Sub

The code is working, but is working for all folders under Inbox, including itself. In other words: the code is marking messages as read on "enviadas" folder but also on "Inbox" folder.

What am I missing here?

Upvotes: 0

Views: 612

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66245

Your event handler and the rule can conflict. And under the PST store provider, message entry ids do not change when an item is moved to a different folder, which means your code (or the rule) can successfully modify the message even if it was already moved to a different folder.

Also, there is no reason to call Item.Save - setting the Unread property does nto require that (it is not part of the message).

Upvotes: 1

Related Questions