I have Sub AutoSendTomorrow()
that gets my calendar info for the next day and emails it to another email address.
I am trying to get it to run, say, everyday at 6pm.
One idea I have, from examples based on incoming mail, is to use event handlers with WithEvents
.
Would the best object to reference for this be the Outlook.Reminders? I was thinking of creating events with the subject along the lines of "Run Macro".
I am also stuck on writing the function that gets triggered.
For the example with the Reminders:
Private With Events trigger As Outlook.Reminders
Sub trigger_ReminderFire(ByVal ReminderObject As Reminder)
'check latest reminder for subject line
'if subject is "Run Macro"
AutoSendTomorrow()
End Sub
I tried a bunch of setups with most of them having a compile error
Only valid in object module
I am using Office 365 Outlook.
The example I was trying to use: https://learn.microsoft.com/en-us/office/vba/api/outlook.reminders.reminderfire
EDIT:
I ended up converting to vbscript. Now I can set a schedule in Task Scheduler in Windows.
Here is my code for reference.
Just to note, the underlying question is not yet answered:
Option Explicit
Dim outlook
Set outlook = CreateObject("Outlook.Application")
Dim oNamespace
Dim oFolder
Dim oCalendarSharing
Dim myDate
Dim oCalMF
Dim oMail
myDate = DateAdd("d", 1, Date)
oCalMF = 0
Set oNamespace = outlook.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(9)
Set oCalendarSharing = oFolder.GetCalendarExporter
With oCalendarSharing
.CalendarDetail = 2
.IncludeWholeCalendar = False
.IncludeAttachments = True
.IncludePrivateDetails = True
.StartDate = myDate
.EndDate = myDate
End With
Set oMail = oCalendarSharing.ForwardAsICal(oCalMF)
oMail.To = "email@email.com"
oMail.Send