• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Use VBA to Email Tomorrow's Agenda

Slipstick Systems

› Outlook › Calendar › Use VBA to Email Tomorrow’s Agenda

Last reviewed on October 26, 2021     18 Comments

Applies to: Outlook (classic), Outlook 2007, Outlook 2010

A user wanted to create a macro that would send his upcoming appointments:

1. Each night at 9:00 pm, email me a snapshot of my calendar for the next day
2. Each Sunday at 9:00 pm, also email me a snapshot of my calendar for the upcoming week (Mon-Sun).

Do you want pretty or just functional? Outlook's Share > Email Calendar function creates a pretty calendar (it can be automated) or you can create a simple list in an email message. The simple list is not pretty (you can use HTMLBody and tags to pretty it up a little) but does the job. To run the macro automatically, you can use a reminder.

If you want to send the calendar in a message you are composing, you can use the Insert > Calendar command. This adds the pretty calendar and the ICS file to the email you are composing. The macro at Add the .ICS file to a message automates adding the ics file as an attachment.

Note: If you see Sharing Permissions when you right click on a calendar (not Share > Email Calendar), and want to manually send a calendar by email, you need to add the Email Calendar command to your ribbon or Quick access toolbar.

pretty calendar free-busy

Pretty Email Agenda

This macro creates a nicely formatted email message, as seen in the screenshot above. I used Free/Busy and Subject for the details. Full Details will include the short list as seen in the screenshot, with the full details below.

Because I'm sending this to myself, I'm removing the .ics file attachment that is normally added to the message.

Public Sub SendPrettyAgenda()
Dim oNamespace As NameSpace
Dim oFolder As Folder
Dim oCalendarSharing As CalendarSharing
Dim objMail As MailItem
Dim wd As Integer

Set oNamespace = Application.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oCalendarSharing = oFolder.GetCalendarExporter

' get the day - send sat/sun/monday out Fri night
' Sun = 1, Mon = 2, Tue = 3, Wed = 4, Thu = 5, Fri = 6, Sat = 7
' none set Sat/Sun
wd = Weekday(Date)
If wd >= 2 And wd <= 7 Then
    lDays = Date + 1
ElseIf wd = 1 Then
    lDays = Date + 7
End If

With oCalendarSharing
' options are olFreeBusyAndSubject, olFullDetails, olFreeBusyOnly
    .CalendarDetail = olFreeBusyAndSubject
    .IncludeWholeCalendar = False
    .IncludeAttachments = False
    .IncludePrivateDetails = True
    .RestrictToWorkingHours = False
    .StartDate = Date + 1
    .EndDate = lDays
End With

' prepare as email
' options: olCalendarMailFormatEventList, olCalendarMailFormatDailySchedule
Set objMail = oCalendarSharing.ForwardAsICal(olCalendarMailFormatDailySchedule)
 
 ' Send the mail item to the specified recipient.
 With objMail
 .Recipients.Add "me@slipstick.com"

' Remove the attached ics
 .Attachments.Remove (1)
 .Display 'for testing, change to .send
 End With

Set oCalendarSharing = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
End Sub

 

Simple List of Appointments

This macro borrows from the code sample at "How to print a list of recurring dates using VBA" to create a simple list of appointments.

I'm only using the Subject, start and end times in this sample, but you can add any appointment field.
Send tomorrow's appointments message

Use HTMLBody and HTML tags to format the list a little better.

Sub CreateListofAppt()
   
   Dim CalFolder As Outlook.MAPIFolder
   Dim CalItems As Outlook.Items
   Dim ResItems As Outlook.Items
   Dim sFilter, strSubject, strAppt As String
   Dim iNumRestricted As Integer
   Dim itm, apptSnapshot As Object
   Dim tStart As Date, tEnd As Date, tFullWeek As Date
   Dim wd As Integer
  
   ' Use the default calendar folder
   Set CalFolder = Session.GetDefaultFolder(olFolderCalendar)
   Set CalItems = CalFolder.Items

   ' Sort all of the appointments based on the start time
   CalItems.Sort "[Start]"
   CalItems.IncludeRecurrences = True

   ' Set an end date
    tStart = Format(Date + 1, "Short Date")
    tEnd = Format(Date + 2, "Short Date")
    tFullWeek = Format(Date + 6, "Short Date")
 
    wd = Weekday(Date)
   ' Sun = 1, Mon = 2, Tues = 3, Wed = 4, Thu = 5, Fri = 6, Sat = 7
' get next day appt, do whole week on sunday
If wd >= 2 And wd <= 6 Then
   sFilter = "[Start] >= '" & tStart & "' AND [Start] <= '" & tEnd & "'"
ElseIf wd = 1 Then
   sFilter = "[Start] >= '" & tStart & "' AND [Start] <= '" & tFullWeek & "'"
End If

Debug.Print sFilter
   Set ResItems = CalItems.Restrict(sFilter)

   iNumRestricted = 0

   'Loop through the items in the collection.
   For Each itm In ResItems
   Debug.Print ResItems.Count
      iNumRestricted = iNumRestricted + 1
      
 ' Create list of appointments
  strAppt = strAppt & vbCrLf & itm.Subject & vbTab & " >> " & vbTab & itm.Start & vbTab & " to: " & vbTab & Format(itm.End, "h:mm AM/PM")

   Next
   
' After the last occurrence is checked
' Open a new email message form and insert the list of dates
  Set apptSnapshot = Application.CreateItem(olMailItem)
  With apptSnapshot
    .Body = strAppt & vbCrLf & "Total appointments; " & iNumRestricted
    .To = "me@slipstick.com"
    .Subject = "Appointments for " & tStart
    .Display 'or .send
  End With

   Set itm = Nothing
   Set apptSnapshot = Nothing
   Set ResItems = Nothing
   Set CalItems = Nothing
   Set CalFolder = Nothing
   
End Sub

 

Use Reminders to trigger the macro

To schedule the macro, you can use a reminder to trigger the macro. For more information on this method, see "Send an Email When a Reminder Fires".

This macro needs to go in ThisOutlookSession; either macro above can go into a new module.

Private Sub Application_Reminder(ByVal Item As Object)
'IPM.TaskItem to watch for Task Reminders
If Item.MessageClass <> "IPM.Appointment" Then
  Exit Sub
End If

If Item.Categories <> "Send Message" Then
  Exit Sub
End If

' call the macro:
SendPrettyAgenda

' or
' CreateListofAppt

End Sub

 

Add the .ICS file to a message

This version of the macro will add the ics file to a message you are already composing. It automates using the Insert > Calendar button but will not add the "pretty" formatted list to the message, only adds the ICS file as an attachment.
availability calendar added as an attachment
As written, the calendar is three business days, starting "tomorrow". It shows only free/busy state and only working hours.
availability calendar next 3 days

To use, add the macro to a button on your ribbon and run it when you need to add your availability to a message.

Public Sub AvailabilityICS()
Dim oNamespace As NameSpace
Dim oFolder As Folder
Dim oCalendarSharing As CalendarSharing
Dim objMail As MailItem ' As Inspector
Dim wd As Integer
Dim lDate As Date
Dim sDtate As Date

Set oNamespace = Application.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oCalendarSharing = oFolder.GetCalendarExporter

' start date tomorrow
sDtate = Date + 1

' end date is 3 business days
' Sun = 1, Mon = 2, Tue = 3, Wed = 4, Thu = 5, Fri = 6, Sat = 7
wd = Weekday(Date)
If wd >= 1 And wd <= 3 Then
    lDate = sDtate + 2
ElseIf wd >= 4 Then
    lDate = sDtate + 4
End If

With oCalendarSharing
' options are olFreeBusyAndSubject, olFullDetails, olFreeBusyOnly
    .CalendarDetail = olFreeBusyOnly
    .IncludeWholeCalendar = False
    .IncludeAttachments = False
    .IncludePrivateDetails = False
    .RestrictToWorkingHours = True
    .StartDate = sDtate
    .EndDate = lDate
End With

SaveAsPath = "D:\Availability from " & Format(sDtate, "mmm dd - ") & Format(lDate, "mmm dd yyyy") & ".ics"
oCalendarSharing.SaveAsICal SaveAsPath

Set objMail = Application.ActiveInspector.CurrentItem
 
 ' Send the mail item to the specified recipient.
 With objMail
  .Attachments.Add SaveAsPath
  .Display
 End With

Set oCalendarSharing = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
End Sub

How to use the macros on this page

First: You need to have macro security set to low during testing. The macros will not work otherwise.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Use VBA to Email Tomorrow's Agenda was last modified: October 26th, 2021 by Diane Poremsky

Related Posts:

  • How to print a list of recurring dates using VBA
  • Copy Recurring Appointment Series to Appointments
  • Combine and Print Multiple Outlook Calendars
  • How to Email Calendar Printing Assistant Calendars

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
18 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Darren
August 16, 2022 10:01 am

How do I make this work with the fire email on reminder script too?

0
0
Reply
Darren
August 11, 2022 11:52 am

How can I add the .ics attachment (I would like to just send all my meetings for that current day till Friday) to the Send email on reminder fire?

0
0
Reply
miguel
February 11, 2022 10:42 pm

Hi there the code works very well, thanks very much for sharing, I have a question, I manage 2 different calendars at the same time, is there a way I can select which calendar I need to share, I am using the "SendPrettyAgenda" code

thanks so mouch again for sharing

0
0
Reply
Claire Purbrick
January 10, 2022 11:13 am

Hi! This is great and really helpful. I manage another person's calendar. Is there a way to run a macro like this for this other person's calendar? Is there a way to add who has accepted or declined a meeting?

Many Thanks!

0
0
Reply
Diane Poremsky
Author
Reply to  Claire Purbrick
January 10, 2022 11:09 pm

You can, but may only be able to send a simple list, not the pretty agenda.

Tio run it manually, change
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oFolder = Application.ActiveExplorer.CurrentFolder.

to automate it, you need use the shared mailbox name -

 Set oFolder = NS.GetSharedDefaultFolder(objOwner, olFolderCalendar)

The full code and instructions are here -
https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#shared

0
0
Reply
Jeff
July 13, 2020 1:02 pm

What can I add to the Reminders to trigger a macro that will automatically dismiss the reminder? I tried adding part of the dismiss reminder script from "Send an Email When a Reminder Fires", but it errors out.

0
0
Reply
Darren
Reply to  Jeff
August 11, 2022 11:54 am

Private WithEvents olRemind As Outlook.Reminders
Dim strSubject As String

Private Sub Application_Reminder(ByVal Item As Object)
Set olRemind = Outlook.Reminders
&nbsp;
'IPM.TaskItem to watch for Task Reminders
If Item.MessageClass &lt;&gt; "IPM.Appointment" Then
&nbsp; Exit Sub
End If
&nbsp;
If Item.Categories &lt;&gt; "Send Message" Then
&nbsp; Exit Sub
End If
&nbsp;
strSubject = Item.Subject
&nbsp; Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
&nbsp;
&nbsp; objMsg.To = Item.Location
&nbsp; objMsg.Subject = strSubject
&nbsp; objMsg.Body = Item.Body
&nbsp; objMsg.Send

&nbsp; Set objMsg = Nothing
&nbsp;&nbsp;
End Sub

Private Sub olRemind_BeforeReminderShow(Cancel As Boolean)

&nbsp; &nbsp; For Each objRem In olRemind
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If objRem.Caption = strSubject Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If objRem.IsVisible Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objRem.Dismiss
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cancel = True
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit For
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If
&nbsp; &nbsp; &nbsp; &nbsp; Next objRem

End Sub

0
0
Reply
Andy
September 25, 2019 9:49 am

I manage a conference room that remains locked. About 30 minutes before a meeting I email our security asking them to unlock the door. I'm looking for a way to have that automated. I used the 'Use reminders to trigger macro' and the Pretty email agenda' macro which worked great and sent me the agenda. How do I add text to that email to ask security to unlock the door for the extent of the meeting?

0
0
Reply
Kiwi
April 1, 2019 8:47 pm

Hi,

Thank you for sharing, it's really helpful.
Is it possible to add a condition if any appointment falls before a certain time? i.e. I would like to be notified if I have a meeting before I start work or starting within the first 15 minutes (09:00-09:15).

Many thanks!

0
0
Reply
RXN
November 20, 2018 12:54 pm

Hello,

This is very, very helpful.

However, I'm very new to VBA and was wondering what changes would need to be made in order to adjust this script so that it creates a snapshot only of Today's calendar and it doesn't even need to send anything automatically.

My plan is to have QAT macro that will open new email with the snapshot of my today's calendar.

I attempted to do this on my own but I haven't had much success.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 32

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment