I have a VBA script in outlook that is designed to do some automatic email handling based on when items are placed in folders. That works as intended, but I'm trying to make it a little more intelligent so the script can see whether or not the email being placed into the folder has been replied to.
Currently, the moment a mail is placed in folder X, the script sends an automatic reply to the email and then marks the mail as unread. However if a mail has already been flagged as "replied", regardless of if the script replied to the mail or if someone sent a reply before placing the mail into folder X, I want to make sure the script does NOT send a reply, and simply marks the mail as unread. Is this something that's possible to do by reading IMAP property tags? If so, which tag am I looking for? I've been struggling to figure out how to accomplish this. Any help would be appreciated.
For reference, here's the script I have (with identifying details removed):
Note: I am aware I have some declared variables but not referenced. I'm going to use these later for something else.
Option Explicit
'##############################################
'### all code for the ThisOutlookSession module
'### Module level Declarations
'expose the items in the target folder to events
Dim WithEvents ackSpamMsgs As Items
Dim WithEvents ackPhishMsgs As Items
Dim WithEvents fwdMsgs As Items
'###############################################
Private Sub Application_Startup()
'some startup code to set our "event-sensitive"
'items collection
Dim objNS As Outlook.NameSpace
Dim ackFolder As Folder
Dim compFolder As Folder
Set objNS = Application.GetNamespace("MAPI")
Set ackMsgs = objNS.Folders("Inbox").Folders("Folder X").Items
Set fwdMsgs = objNS.Folders("Inbox").Folders("Folder Y").Items
End Sub
'#################################################
'### this is the ItemAdd event code
Sub ackMsgs_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder"
'we can process it
Dim msg As MailItem
Set msg = Item.Reply
'This is where I want to check if the mail has been replied to, and skip the "with"
'below if it has been replied to.
With msg
.Subject = "RE: " & Item.Subject
.HTMLBody = "Body of email here"
.Send
Set msg.UnRead = True
End With
End Sub
Sub fwdMsgs_ItemAdd(ByVal Item As Object)
Dim msg As MailItem
Dim newMsg As MailItem
Set msg = Item.Forward
msg.Recipients.Add ("email@email.com")
msg.Send
End Sub
'#################################################
Private Sub Application_Quit()
Dim objNS As Outlook.NameSpace
Set ackMsgs = Nothing
Set fwdMsgs = Nothing
Set objNS = Nothing
End Sub