More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 23-Apr-2019 02:57

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

" AddApptRow = strRow End Function Function Quote(MyText) Quote = Chr(34) & MyText & Chr(34) End Function
Code level: beginner    Code area: Basic Outlook Printer Friendly Version
Title: Sending a mail message with today's appointments
Description: Tnis code generates an HTML-format mail message containing a list of today's appointments. It may look complicated, but it uses nothing but basic methods and properties -- mainly Items.Restrict (see related article at, MailItem.HTMLBody, and the properties of an AppointmentItem. In case you're not familiar with HTML tables, the basic syntax -- which the AddApptRow routine helps to construct -- is:
1st row, 1st col 1st row, 2nd col
2nd row, 1st col 2nd row, 2nd col
You can add formatting to the basic structure using standard HTML tags and attributes.
Date: 23-Oct-2002  06:42
Code level: beginner
Code area: Basic Outlook
Posted by: Sue Mosher
This message is displayed as VB.NET
 Sub MailTodaysAppts()
  Call MailAnyDaysAppts(Date + 1)
End Sub

Sub MailAnyDaysAppts(dteDate As Date)
  Dim objApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim colCal As Outlook.Items
  Dim strFind As String
  Dim colMyAppts As Outlook.Items
  Dim objAppt As Outlook.AppointmentItem
  Dim objMsg As Outlook.MailItem
  Dim strHTML As String
  ' start HTML for message
  strHTML = "

Here are my appointments for " & _ FormatDateTime(dteDate, vbLongDate) & _ ":

" Set objApp = CreateObject("Outlook.Application") Set objNS = Application.GetNamespace("MAPI") Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items colCal.Sort "[Start]" colCal.IncludeRecurrences = True ' get appointments spanning date strFind = "[Start] < " & _ Quote(Format(dteDate, "dd mmm yyyy") & " 12:00 AM") & _ " AND [End] > " & _ Quote(Format(dteDate, "dd mmm yyyy") & " 12:00 AM") Debug.Print strFind Set colMyAppts = colCal.Restrict(strFind) For Each objAppt In colMyAppts strHTML = strHTML & AddApptRow(objAppt) Next Set colMyAppts = Nothing ' get appointments starting on date strFind = "[Start] >= " & _ Quote(Format(dteDate, "dd mmm yyyy") & " 12:00 AM") & _ " AND [Start] < " & _ Quote(Format(dteDate + 1, "dd mmm yyyy") & " 12:00 AM") Debug.Print strFind Set colMyAppts = colCal.Restrict(strFind) For Each objAppt In colMyAppts strHTML = strHTML & AddApptRow(objAppt) Next ' create new message Set objMsg = objApp.CreateItem(olMailItem) With objMsg .Subject = "Appointments for " & _ FormatDateTime(dteDate, vbLongDate) .HTMLBody = strHTML & "
" .Display End With Set objApp = Nothing Set objNS = Nothing Set colCal = Nothing Set colMyAppts = Nothing Set objAppt = Nothing End Sub Function AddApptRow(objAppt As Outlook.AppointmentItem) As String Dim strRow As String strRow = "
" If objAppt.AllDayEvent = True Then strRow = strRow & "All day" Else strRow = strRow & _ FormatDateTime(objAppt.Start, vbShortTime) & _ " - " & FormatDateTime(objAppt.End, vbShortTime) End If strRow = strRow & "" & _ objAppt.Subject If objAppt.Location <> "" Then strRow = strRow & " (" & _ objAppt.Location & ")" End If strRow = strRow & "

" If objAppt.Body <> "" Then strRow = strRow & objAppt.Body & "

" End If strRow = strRow & "
All 99comments
Page [ 1 2 3 4 5 6 7 8 9 10 Next >>  
  24-Oct-2002  06:42   
Let's try that again. Here's the raw HTML to represent a table:

        <td>1st row, 1st col</td>
        <td>1st row, 2nd col</td>
        <td>2nd row, 1st col</td>
        <td>2nd row, 2nd col</td>

  24-Oct-2002  19:23   
Great & very useful Thanks, hope you can help, I've tried to change to point to my journal folder, as it would be very useful to capture this data, but very new to this so unsure which bits need amending (have ordered the book & look forward to it's arrival)


  15-Nov-2002  16:07   
Several things to change:

1. Declare a variable for each journal item you'll process:

  Dim objJournal As Outlook.JournalItem

2. Get the Journal folder instead of the Calendar folder:

  Set colCal = objNS.GetDefaultFolder(olFolderJournal).Items

3. Leave out the IncludeRecurrences statement, because journal items are not recurring.

4. Modify the AddApptRow to build the table from the JournalItem properties that you want to use. You can look up the property names in the Object Browser -- Press Alt+F11 to get into the VBA environment, then F2 for the Object Browser. The object you want to look at is JournalItem.

Have fun!

  03-Dec-2002  10:24   
I am new at this. Where do I put this code? In a button or on a web page?

  07-Jan-2003  22:08   
Hi, Barb. Welcome! The fact that this code has typed variable declarations (e.g. Dim objApp As Outlook.Application) is the tipoff that this is VBA or VB code. If you add it to VBA in Outlook (Alt+F11), you can run it from the Tools | Macros dialog or customize the toolbar or menu to add a command to run the MailTodaysAppts macro. If you're totally new to VBA, the article at should give you the essentials.

  20-Feb-2003  11:28   
I'm new to programming but I copied the code above into a new module and ran the macro. First I got an error on the very last line of the code - I changed it to End Function and got my next error - type mismatch or the value "21 Feb 2003 12:00 AM" in the condition is not valid. I'm on NT4 w/Outlook2000 on Exchange 5.5. Is this a date time formatting problem in the code or due to my system settings or ...?
  03-Mar-2003  18:18   
Roger, try changing the date format from "dd mmm yyyy" to "ddddd" -- I've seen that help sometimes.
  31-Mar-2003  15:28   
I changed the "dd mmm yyyy" to "ddddd" and that did the trick. Thanks for a great site! I'll be buying the book soon!
  12-Apr-2003  16:53   
How would you suggest using GetDefaultFolder to look at a Public Calendar instead of the user's local calendar?
  12-Apr-2003  17:08   
I'm a beginner and managed to scrape this code together to reference a public folder. Is this the most efficient to call up the items?: Set colCal = objApp.GetNamespace("Mapi").GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A03001CF93BFDCA3E8042888992CEFCEEACA2000000001F4B0000").Items

Page [ 1 2 3 4 5 6 7 8 9 10 Next >>