How do I mark emails already received as read when I get a second, different email based on subject?

Not open for further replies.


New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
How do I mark emails already received as read when I get a second, different email based on subject which is different but similar?

So lets say I get an email with the subject:
[zenoss] **

A minute later I get an email with the subject:
[zenoss] CLEAR: **

Can someone help me figure out how fix my code below? Or fix my operator error... I've never made outlook macros so I might be failing at something obvious:

Const PST1_NAME = "test"
Const PST2_NAME = "test2"
Const FOLDER1_NAME = "Alerts - Zenoss"
Const FOLDER2_NAME = "Alerts - Zenoss - CLEAR"

' sample with hardcoded psts & folders
Private Sub markDuplicateEmails()
End Sub

' actual method which takes dynamic pst\folder source and destination
Public Sub markDuplicates(source, destination, category)
Dim myOlApp, myNameSpace
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")

Dim tmpArray, pst1Name, pst2Name, folder1Name, folder2Name
tmpArray = Split(source, SEPERATOR)
pst1Name = tmpArray(0)
folder1Name = tmpArray(1)
tmpArray = Split(destination, SEPERATOR)
pst2Name = tmpArray(0)
folder2Name = tmpArray(1)

Dim folder1Size, folder2Size
folder1Size = myNameSpace.Folders(pst1Name).Folders(folder1Name).Items.Count
folder2Size = myNameSpace.Folders(pst2Name).Folders(folder2Name).Items.Count

Dim array1(), array2()
ReDim array1(folder1Size)
ReDim array2(folder2Size)

Dim outlookItem1, outlookItem2, i, j
Dim theCstmData

'populate array1
i = -1
For Each outlookItem1 In myNameSpace.Folders(pst1Name).Folders(folder1Name).Items
i = i + 1
Set theCstmData.item = outlookItem1
theCstmData.Subject = outlookItem1.Subject(8, Subject.Length - 30)
array1(i) = theCstmData
Next outlookItem1

' populate array2
i = -1
For Each outlookItem2 In myNameSpace.Folders(pst2Name).Folders(folder2Name).Items
i = i + 1
Set theCstmData.item = outlookItem2
theCstmData.Subject = outlookItem2.Subject(15, Subject.Length - 30)
array2(i) = theCstmData
Next outlookItem2

'loop through each item in array1
For i = 0 To folder1Size - 1
'loop through each item in array 2 comparing each array2Item with current array1item
For j = 0 To folder2Size - 1
' if it is a match mark the item in array2 as duplicate
If array2(i).Subject = array1(i).Subject Then
If array1(i).item.UnRead = True Then
array1(i).item.UnRead = False
array1(i).item.UnRead = array2(j).item.UnRead & CATEGORY_SEPERATOR
End If

If array2(j).item.UnRead = True Then
array2(j).item.UnRead = False
array2(j).item.UnRead = array2(j).item.UnRead & CATEGORY_SEPERATOR
End If
array2(j).item.UnRead = False
End If
Next j
Next i
End Sub

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I can't say whether or not the logic works. However, if it is expected to run as VBA, then the syntax as far as we can see it isn't ok. This is hard to say as all the variables are declared as Variants instead of the really used types.

Dim theCstmData
The above dims a variable as Variant, which has no properties itself. As the variable isn't set to an object, this must fail because the item property doesn't exist:
Set theCstmData.item = outlookItem1
You'd need to add a class module to the VBA project, and add all the properties to it that are used in the code.

Also, the Outlook item, which is referenced in the for each loops, has a Subject property, which is a string that doesn't take any paramters. So
outlookItem1.Subject(8, Subject.Length - 30)
must fail.

No matter which programing language is used, this one certainly makes no sense at all:
array1(i).item.UnRead = array2(j).item.UnRead & CATEGORY_SEPERATOR
Joining True/False, or -1/0 respectively, with a string results in a string, and writing anything but "0" to a boolsche variable (Unread) will always result in True.

I'd say, contact your operator and have him fix the code, or get your money back.


New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
heh there was no money. I tried to break someones free code down from online and format it to what I need. But I'm as you can see, not a programmer, so I tried to convert data that is a string and I apparently deleted references accidentally as well, I'll look into those to see what I deleted and see if I can patch it together

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I use this - - it's used in a run a script rule.

Do you need to watch a lot of folders? Looping through all folders looking for a match can be time consuming, especially if you have a lot of folders. If you're doing this with each new message, it's likely some will be skipped.

As long as all older messages with [zenoss] in the subject are to be marked read, you can use either instr or left to lool for a match.
Not open for further replies.
Thread starter Similar threads Forum Replies Date
DoctorJellybean Outlook 365 doesn't always mark emails as read Using Outlook 3
C Mark all incoming emails as read Outlook VBA and Custom Forms 3
V Mark BCC when emails is sent from specific account Outlook VBA and Custom Forms 2
N Mark or follow up emails in shared mailbox Using Outlook 2
J Exchange 2010: Microsoft Outlook Web App: How do you mark specific emails as junk? Exchange Server Administration 1
E aol emails automatic mark as read and delete__ Using Outlook 1
I Pound Symbol in emails show as � (black diamond with white question mark inside) - Office 2010. Using Outlook 11
O Office 365 Outlook - mark to download Using Outlook 0
S Codes for "Mark Complete" the task Outlook VBA and Custom Forms 2
S Mark as Unread unless Categorized by Color Using Outlook 0
Diane Poremsky Mark Sent Items as Read After Copying with a Rule New Articles 0
M Mark Complete keyboard shortcut... on a mac running Windows Bootcamp Using Outlook 0
T Adding "Mark As Complete" btton to Task Remindet Pop-Up Using Outlook 3
F Automatically close email after selecting mark unread Using Outlook 1
T Outlook 2013 either fails to mark messages as read or marks them as read, then un-marks them. Using Outlook 1
Mary B VBscript: Need to copy every email to a folder & mark that copy as read Outlook VBA and Custom Forms 5
T outlook 2013 does not mark multiple forward messages as forward Using Outlook 2
7 Macro to mark message as junk and delete Outlook VBA and Custom Forms 3
B Outlook 2010: how to mark messages without opening? Eg for deletion Using Outlook 2
Z Mark moved copies as "Read" Using Outlook 19
Z "Mark All as Read" in Outlook 2007 extremely slow Using Outlook 1
H mark as read per folder options Using Outlook 1
C Outlook 2010 search for question mark in calendar Using Outlook 7
M Can't mark appointments as private for other user Using Outlook 1
R Outlook 2010 Quick Steps - Mark as Read Action and New Mail Notification Using Outlook 1
L Outlook / messages not mark as been read Using Outlook 1
C Outlook 2003 Exclamation Mark Using Outlook 1
K clicking "completed" icon doesn't mark task complete. Using Outlook 2
M Mail rules: "Mark as read" doesn't work... Using Outlook 1
J Change 'Mark As Read' Status Without using Reading Pane Using Outlook 1
S How do I mark an email I want to send as 'private'? Using Outlook 2
L Apostrophe becomes question mark when posting to a new group using Windows Live mail Using Outlook 3
D Outlook 2010 - Mark Unread button isn't always in the correct state Using Outlook 4
M Mark mail as read on Hotmail server using Connector Using Outlook 2
H Outlook 2007 Errors-Out/Restarts Trying to Print an Email with MS-Word Mark-Up Area Using Outlook 1
D In the last few days I get error message box indicating with a Red X mark and 'This operaion has been cancelled due to restriction on this comput Using Outlook 3
S Flagging Messages - Cannot 'Mark Complete'! Using Outlook 1
K Right-Click to Mark ALL as Read on (Exchange) Public Folder Using Outlook 1
F Mark RSS as read Using Outlook 1
J Paragraph Mark Using Outlook 1
J being able to mark read messages to unread using a Macbook that uses Safari in OWA Using Outlook 2
J Be able to mark email as unread in OWA Using Outlook 2
S Mark all as read not working for RSS feeds Using Outlook 1
J Conflict between "Unread Mail" and "Mark items as read when viewed in the reading pane" Using Outlook 2
A Mark all as read for public folders Using Outlook 14
S Outlook message subject changed to question mark after importing pst. ??????? Exchange Server Administration 2
J Mark recurring event as completed for individual event Using Outlook 1
J Outlook 2010 - IMAP "Mark items for deletion" does not work Using Outlook 4
N Changing the 'Mark item as read when selection changes' at runtime Outlook VBA and Custom Forms 1
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
Similar threads