I cannot thank you enough and I am hoping that this will be the last time that I have to bug you as I am so close to achieving what I wanted.
With a bit of tweaking I managed to get this to work, I also added the code to check the sender name but as it is sent to multiple names and can be sent back by one name I decided that just checking the subject line will be enough. However I know have the problem that the original subject line won’t match the new subject line if the person has responded to the chaser email as it will now read "Urgent Chaser - Subject".
I tried adding the "Urgent Chaser -" to the subject line of the existing email in the waiting for reply folder but as the new one contains “Re:” I can’t match them. Is it possible to code for a wildcard and if so what is the code?
PHP Code:
Private Sub Application_NewMail()
Dim i As MailItem, a As Attachment, s As MailItem
Dim e As Outlook.MailItem
Dim h As Outlook.MailItem
Dim OutApp As New Outlook.Application
Dim oMAPI As Outlook.NameSpace
Dim oParentFolder As Outlook.MAPIFolder
Dim oFolder As Outlook.folder
Dim olObject As Object
'***********************************************************************
'Find New email
Set olObject = Application.Session.GetDefaultFolder(olFolderInbox).Items.GetFirst()
'***********************************************************************
'Set email folders
Set oMAPI = OutApp.GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Maxwell, Oliver: Ops Client Services (LDN)") 'Set mail box where the emails are
Set f = oParentFolder.Folders("Inbox")
Set g = oParentFolder.Folders("Inbox").Folders("waiting for reply")
'***********************************************************************
'Check new emails and match with emails held in Waiting for Reply
For Each e In g.Items
If InStr(e.ConversationTopic, olObject.ConversationTopic) > 0 Then ' match
e.Move f
Exit For ' stop looking
End If
Next e
End Sub
Secondly and this is driving me mad, I have manged to mess something up with the setting the Original, can you take a look at the code as I cannot see what I need to change. Ever time I hit Set Origianl = f in CASE 4 I get RUn-time error '13': Type mismatch.
PHP Code:
Sub ApplicationReminder()
Dim m As Outlook.MailItem
Dim r As Outlook.MailItem
Dim eindex As Integer
Dim Original As Outlook.MailItem
Dim OutApp As New Outlook.Application
Dim oMAPI As Outlook.NameSpace
Dim oParentFolder As Outlook.MAPIFolder
Dim oFolder As Outlook.folder
'***********************************************************************
'Set email folders
Set OutApp = New Outlook.Application
Set oMAPI = OutApp.GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Mailbox - Maxwell, Oliver: Ops Client Services (LDN)") 'Set mail box where the emails are
Set f = oParentFolder.Folders("Inbox").Folders("waiting for reply")
Set g = oParentFolder.Folders("Inbox").Folders("No Reply Received")
'************************************************************************
For eindex = f.Items.Count To 1 Step -1
Select Case Now - f.Items(eindex).SentOn
Case Is > 5 + IIf(Weekday(Date) > 0, 2, 0) ' Move Emails over 5 days to No Reply Recieved
f.Items(eindex).Move g
'**********************************************************************
Case Is > 4 + IIf(Weekday(Date) > 1, 2, 0) ' Send final chaser for all emails over 4 days
Set Original = f
Set r = f.ReplyAll
r.Attachments.Add Original
r.SentOnBehalfOfName = "ecommerceonboardingemea"
r.CC = "ecommerceonboardingemea"
r.Subject = "Urgent Chaser - " & f.Subject
r.Body = "Please provide a response to the attached email within 24hrs or the request/action will be archived due to no response." & f.Body
r.Display ' Change to send
'**********************************************************************
Case Is > 2 + IIf(Weekday(Date) > 3, 2, 0) ' Send initial chaser for all emails over 2 days
Set Original = f
Set r = f.ReplyAll
r.Attachments.Add Original
r.SentOnBehalfOfName = "ecommerceonboardingemea"
r.CC = "ecommerceonboardingemea"
r.Subject = "Urgent Chaser - " & m.Subject
r.Body = "Please provide a response to the attached email." & m.Body
r.Display ' Change to Send
End Select
Next
End Sub