Microsoft Office Tutorials and References
In Depth Information
The new appointment is, of course, blank — you must fill in the various details such as subject,
start/stop times, and whether a reminder will be displayed. A new appointment created in code is
not visible on the screen. There are two approaches to filling in the details of a new appointment.
You can do it all in code without ever making the appointment visible to the user. In this case you
must save the appointment by calling the Save() method:
Dim NewAppt As Outlook.AppointmentItem
Set NewAppt = CreateItem(olAppointmentItem)
NewAppt.Subject = “Sales review meeting”
NewAppt.Location = “ Conference Room B”
NewAppt.Start = #9/26/2006 1:00:00 PM#
NewAppt.End = #9/26/2006 3:00:00 PM#
NewAppt.Body = “Make sure to bring the worksheet.”
The other approach is to display the appointment to the user by calling its Display() method.
The user fills in the appointment details and saves it by clicking the Save & Close button, as usual.
Accessing Existing Appointments
You access existing appointments using the Calendar folder’s Items collection. You can retrieve
an appointment based on its subject. Here’s how to retrieve an appointment by its subject, in this
case “New Employee Training” (assume that CalendarFolder is a reference to Outlook’s
Calendar folder):
Dim MyAppt As Outlook.AppointmentItem
Set MyAppt = CalendarFolder.Items(“New Employee Training”)
The problem with this approach is that if there are multiple appointments with the same subject,
it retrieves only the first one. It is preferable to loop through all the appointments in the folder
with a For Each...Next statement, looking for one or more appointments of interest. Here’s an
example that sets the variable MyAppt to point at the first appointment that has “New Employee
Training” as its subject. If there is no such appointment, a message is displayed alerting the user.
If you try to retrieve an appointment by subject and there is no matching appointment,
a runtime error occurs. This error can be trapped, but it is better to avoid trying to
retrieve individual appointments in this manner.
Dim MyAppt As Outlook.AppointmentItem
Dim Appt As Outlook.AppointmentItem
Dim Found As Boolean
Found = False
For Each Appt In CalendarFolder.Items
If Appt.Subject = “New Employee Training” Then
Found = True
Set MyAppt = Appt
Search JabSto ::

Custom Search