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:
- Setup a task with a subject line that will match the string in the VBA code, make it recurring and set a reminder for the future.
- My code is in "ThisIOutlookSession".
My code:
- Sets Application_Reminder as an object
- Sets DIM as mailItem and strbody(for body of string)
- If Item.Class = OlTask Then
- look in substring for item with subject "api movements recurring email" Then
- If true uses the variable to create an email
- strbody of the email
- WITH statements to include subject, to addresses, HTMLbody, and attachments.
- sends the email
- many ElseIf statements to include multiple emails.
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