0

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
Community
  • 1
  • 1
Kayracer
  • 169
  • 3
  • 13
  • Task Scheduler is a good process to use for this: https://www.thespreadsheetguru.com/blog/how-to-automatically-run-excel-vba-macros-daily – Tragamor May 19 '21 at 12:17
  • @Tragamor I think the .Run method is depreciated. I updated my question to include that I am using Outlook from O365 – Kayracer May 19 '21 at 17:24
  • 2
    Does this answer your question? [How to add MS outlook reminders event handlers with VBA](https://stackoverflow.com/questions/7054453/how-to-add-ms-outlook-reminders-event-handlers-with-vba) – niton May 19 '21 at 21:41

0 Answers0