Reputation: 13
I am writing code for emails I send quarterly and monthly.
My Problem: It will not send any emails after I got it working yesterday.
Steps:
My code:
Yesterday I had the monthly emails set up to run, and they did.
I think the issue is: The tasks being created, or perhaps it is the application reminder object. Also, I wonder if olTask is not appropriate for recurring tasks for this to run because perhaps the tasks change after their due date. I also tried completing the tasks and then sending the reoccurrence, but that didn't work either.
My code (I deleted sensitive information. There are 11 emails but I only show two for the sake of reviewing it all.):
Private Sub Application_Reminder(ByVal Item As Object)
Dim objPeriodicalMail As MailItem
Dim strbody As String
If Item.Class = olTask Then
'change the following item subject so it knows what to send
If InStr(LCase(Item.Subject), "api movements recurring email") Then
Set objPeriodicalMail = Outlook.Application.CreateItem(olMailItem)
'Change the following email information as per your actual needs
strbody = "<H3><B>Hi Sanmin,</B></H3>" & _
"I hope this e-mail finds you well. This is a friendly reminder to please send the completed API material movements checklist for this month by the first business day of the coming month. I have attached the month-end checklist for your use. If there are no API movements in transit at the end of the month, please send me an e-mail stating so." & _
"<br><br><B>Thank you,</B>" & _
"<br><br><br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B>P : </B>" & _
"<br><B>E: </B>"
With objPeriodicalMail
.Subject = "API Movements Report"
.To = ""
'.To = ""
'.CC = ""
.HTMLBody = strbody & .HTMLBody
.Attachments.Add "C:\Automated Emails\API In-Transit Material Movements Checklist.xlsx"
.Send
End With
'change the following item subject so it knows what to send
ElseIf InStr(LCase(Item.Subject), "beth quarterly recurring email") Then
Set objPeriodicalMail = Outlook.Application.CreateItem(olMailItem)
'Change the following email information as per your actual needs
strbody = "<H3><B>Hi Beth,</B></H3>" & _
"" & _
"<br><br><B>Thank you,</B>" & _
"<br><br><br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>" & _
"<br><B></B>"
With objPeriodicalMail
.Subject = "Quarterly Inventory Reserve Inquiry"
.To = ""
'.To = ""
'.CC = ""
.HTMLBody = strbody & .HTMLBody
.Send
End With
End If
End If
End Sub
Upvotes: 1
Views: 182
Reputation: 49455
Your code is valid, I don't see any possible causes that could stop it from running. You can set a breakpoint and wait until the reminder event is fired, so you will be able to debug the code and see how it is working.
But VBA macros can be disabled in Outlook and your code may never run. I'd suggest checking the Trust Center settings in Outlook to make sure VBA macros are not disabled.
Another possible alternative is timers. See Outlook VBA - Run a code every half an hour for more information.
Upvotes: 1