Microsoft Office Tutorials and References
In Depth Information
The macro MoveMessages is listed in the Macros dialog box.
Creating a Summary of Upcoming
The demonstration that is presented here serves two purposes. First, it presents a useful example of
using VBA to work with your calendar items. Second, it shows how to work with Outlook Notes
programmatically. In addition, it shows you some of the things you can do with dates in VBA.
This application is a macro — that is, it is a Sub procedure with no arguments. I have named it
ListAppointmentsThisWeek . Its operation proceeds as follows:
Get a reference to the default Calendar folder (as was described in Chapter 24).
Create a date that is one week from the present.
Create the note heading (the first line of the note) that consists of the text Week of
followed by today’s date. You’ll recall from Chapter 13 that the first line of a note is
automatically used as its subject.
Loop through all appointments in the folder using a For Each...Next loop.
Examine each appointment’s start date — it must be greater than or equal to today’s date
and less than or equal to the date you created one week hence.
If the appointment meets these criteria, extract the required information from it.
When all appointments have been processed, create and display the note.
The technique used here to compile all the information from all matching appointments is to create
a string variable and add each additional bit of information to the end of the string. Note the use of
the constant vbCrLf , which is the newline character — it moves everything that follows to the