Public Sub ProcessingzabbixEmails(Item As Outlook.MailItem)
Dim objFolder As Outlook.Folder
Dim strSubject As String
Dim objProbEmail As Outlook.MailItem
If Right(Item.Subject, 2) = "OK" Then
Set objFolder = Outlook.Session.Folders("YourArchiveNameHere")
' Find Matching Email
strSubject = Left(Item.Subject, Len(Item.Subject - 2)) & "PROBLEM"
Set objProbEmail = Item.Parent.Items.Find("[Subject] = " & strSubject)
objProbEmail.UnRead = False
Item.Move objFolder
objProbEmail.Move objFolder
Item.UnRead = False
Item.Move objFolder
End If
End Sub
' Find Matching Email
strSubject = Left(Item.Subject, (Len(Item.Subject) - 2)) & "PROBLEM"
Set objF = Session.Folders("MainFolder").Folders("SubFolderName")
Set objF = Session.Folders("Archive").Folders("Archived Production Alerts")
Debug.Print Replace(strSubject, "'", "''")
right after
strSubject = Left(Item.Subject, Len(Item.Subject) - 2) & "PROBLEM"
to verify what subject it is trying to find. Also put
Debug.Print objProbEmail.Subject
right after
Set objProbEmail = objProductionFldr.Items.Find("[Subject] = '" & Replace(strSubject, "'", "''") & "'")
to see what it found.
When the new messages arrive that you want to leave as unread - do you leave those as unread or do we have to try to manage keeping these marked as unread (this is difficult and may be impossible based on how you use outlook).
If you leave those as unread, then really we just need a solution to manage moving the matching emails. At that point I suggest creating a rule that runs each time you receive an email from your system. In the rule, have it run a script and then put this macro into a module in the Outlook VBA:
Open in new window