Reputation: 175
I have created a rule in my Outlook. This rule exports some of my emails to a folder called "Others", if their subjects contain a specific word. Through VBA, I want to automatically mark all emails in the folder "Others" as read, either when I start outlook or when I receive the emails that need to go to the folder "Others".
Upvotes: 3
Views: 10816
Reputation: 12499
Make sure your macro security settings are set correctly:
for Outlook 2010 and up: File, Options, Trust Center, Trust Center Settings, Macro Security otherwise, you'll need to use selfcert.exe to sign your macros to test them which I highly recommended
Email will be marked read when it is moved to a subfolder ("Others") of the inbox.
Place the code in ThisOutlookSession module, you must restart Outlook.
Tested on Outlook 2010
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set Folder = olNs.GetDefaultFolder(olFolderInbox)
'// change the folder if need here
Set Folder = olFolder.Folders("Others")
Set Items = Folder.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Upvotes: 4