title: Trigger macro at a specific time
body: <p>I have <code>Sub AutoSendTomorrow()</code> that gets my calendar info for the next day and emails it to another email address.</p>
  <p>I am trying to get it to run, say, everyday at 6pm.</p>
  <p>One idea I have, from examples based on incoming mail, is to use event handlers with <code>WithEvents</code>.</p>
  <p>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 &quot;Run Macro&quot;.</p>
  <p>I am also stuck on writing the function that gets triggered.</p>
  <p>For the example with the Reminders:</p>
  <pre class="lang-vb prettyprint-override"><code>Private With Events trigger As Outlook.Reminders
  Sub trigger_ReminderFire(ByVal ReminderObject As Reminder)
      'check latest reminder for subject line
      'if subject is &quot;Run Macro&quot;
      AutoSendTomorrow()
  End Sub
  </code></pre>
  <p>I tried a bunch of setups with most of them having a compile error</p>
  <blockquote>
  <p>Only valid in object module</p>
  </blockquote>
  <p>I am using Office 365 Outlook.</p>
  <p>The example I was trying to use: <a href="https://docs.microsoft.com/en-us/office/vba/api/outlook.reminders.reminderfire" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/office/vba/api/outlook.reminders.reminderfire</a></p>
  <p>EDIT:<br />
  I ended up converting to vbscript. Now I can set a schedule in Task Scheduler in Windows.</p>
  <p>Here is my code for reference.</p>
  <p>Just to note, the underlying question is not yet answered:</p>
  <pre><code>Option Explicit
  Dim outlook
  Set outlook = CreateObject(&quot;Outlook.Application&quot;)
   
  Dim oNamespace
  Dim oFolder
  Dim oCalendarSharing
  Dim myDate
  Dim oCalMF
  Dim oMail    
  
  myDate = DateAdd(&quot;d&quot;, 1, Date)
  oCalMF = 0
  
  Set oNamespace = outlook.GetNamespace(&quot;MAPI&quot;)
  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 = &quot;email@email.com&quot;
  oMail.Send
  </code></pre>