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

Status
Not open for further replies.

Mari

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"
Const CATEGORY_SEPERATOR = ","

' sample with hardcoded psts & folders
Private Sub markDuplicateEmails()
markDuplicates PST1_NAME & SEPERATOR & FOLDER1_NAME, PST2_NAME & SEPERATOR & FOLDER2_NAME, DEFAULT_CATEGORY
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
DoEvents
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
DoEvents
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
Else
array1(i).item.UnRead = array2(j).item.UnRead & CATEGORY_SEPERATOR
End If
array1(i).item.Save

If array2(j).item.UnRead = True Then
array2(j).item.UnRead = False
Else
array2(j).item.UnRead = array2(j).item.UnRead & CATEGORY_SEPERATOR
End If
array2(j).item.UnRead = False
array2(j).item.Save
End If
DoEvents
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.
 

Mari

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 - http://www.slipstick.com/developer/delete-older-messages-new-message-arrives/ - 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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title 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
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 Slipstick.com 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
A Mark all as read for public folders Using Outlook 14
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
B Mark copy of sent email as read - VBA? Outlook VBA and Custom Forms 3
J Pasting into Outlook 2003 produces blue question mark Using Outlook 2
J Mark as read Outlook VBA and Custom Forms 2
M Mark as read Outlook VBA and Custom Forms 5
R Macro to mark item unread Outlook VBA and Custom Forms 2
T Setting a delegate to not mark items as read Using Outlook 9
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
B Outlook 2016 Unable to view images or logos on the outlook 2016 emails the same html code works well when i use outlook 2010 Using Outlook 0
A Record opened emails for reopening later Using Outlook 2
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
S Outlook 2016 Change how Outlook shows me contacts in emails Using Outlook 0
T Outlook creating unwanted tasks in Tasks and Todo from emails Using Outlook 1
Horsepower Moving emails between folder Outlook for Mac Outlook Wishlist 8
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
L IMAP Emails Disappear Using Outlook 0
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
S Macro to extract and modify links from emails Outlook VBA and Custom Forms 3
D Duplicate Emails on Phone and Tablet Using Outlook 0
S Macro for Loop through outlook unread emails Outlook VBA and Custom Forms 2
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
P Forwarding emails issue with special characters replacing text body Using Outlook 1
B Emails get stuck in Outbox of Gmail IMAP in Outlook for Windows Using Outlook 0
C Multiple emails Using Outlook 3
Phillip Bit.ly emails Using Outlook 1

Similar threads

Top