AppointmentItem 对象 (Outlook)
代表“日历”文件夹中的会议、一次性约会、定期约会或会议。
备注
使用 CreateItem 方法创建表示新约会的 AppointmentItem 对象。
使用 Items (索引) ,其中 index 是约会的索引号或用于匹配约会的默认属性的值,以便从日历文件夹中返回单个 AppointmentItem 对象。
还可以使用 GetAssociatedAppointment 方法从 MeetingItem 对象返回 AppointmentItem 对象。
当使用定期约会项目时,应释放任何先前的引用、 访问或修改项目,并释放这些引用,一旦完成并保存所做的更改之前获取新的定期约会项引用。 这种做法适用于周期性的 AppointmentItem 对象,以及任何 异常 或 RecurrencePattern 对象。 若要释放 (VBA) 或 Visual Basic 中 Visual Basic for Applications 的引用,设置为 Nothing ,现有对象。 在 C# 中,明确释放相应对象占用的内存。
请注意,即使是在您释放引用并尝试获取新引用之后,如果仍存在对以上对象之一的活动引用(由另一个加载项或 Outlook 保存),则新引用也仍将指向对象的过期副本。 因此,在完成定期约会之后立即释放引用非常重要。
VBA 中的以下代码示例显示如何释放和更新引用,以获得定期约会的更新数据。 此示例从“日历”文件夹中获得一组约会项。 它假定约会集合中的第一个项目是定期约会的一部分。 该示例演示对在创建异常之前获取的约会集合的引用不会反映该异常情况。 接着,该示例释放此引用和其他现有的约会引用,在此之后,指向约会集的新引用将反映该异常情况。
Sub TestExceptions()
Dim oItems As Items
Dim oItemOriginal As AppointmentItem
Dim oItemNew As AppointmentItem
Dim rPattern As RecurrencePattern
Dim oEx As Exceptions
Dim oEx2 As Exceptions
Dim oOccurrence As AppointmentItem
Dim i As Long
' This is the initial reference to an appointment collection.
Set oItems = _
Outlook.Application.Session.GetDefaultFolder(olFolderCalendar).Items
' This is the original reference to the first appointment in the
' collection before an exception is created.
Set oItemOriginal = oItems.Item(1)
' Code example assumes that the first appointment in the collection
' is a recurring appointment.
Set oOccurrence = _
oItemOriginal.GetRecurrencePattern().GetOccurrence(#2/28/2010 8:00:00 AM#)
' Create an exception by changing the 2/28 occurrence to 3/3.
oOccurrence.Start = #3/3/2010 8:00:00 AM#
oOccurrence.Save
Stop
' Preexisting reference to the first appointment in the collection
' does not reflect the exception.
oItemOriginal.Save
Set oEx = oItemOriginal.GetRecurrencePattern().Exceptions
Debug.Print oItemOriginal.subject
Debug.Print " Original item exceptions: " & oEx.Count
' Get a new reference based on the existing reference to the
' appointment collection created before the exception.
' The new reference does not reflect the exception.
Set oItemNew = oItems.Item(1)
oItemNew.Save
Set oEx2 = oItemNew.GetRecurrencePattern().Exceptions
Debug.Print " New item exceptions: " & oEx2.Count
' Same: preexisting reference to the first appointment in the collection
' does not reflect the exception.
Set oEx = oItemOriginal.GetRecurrencePattern().Exceptions
Debug.Print " Original item exceptions: " & oEx.Count
' Release all existing references to appointment items,
' including the appointment collection, an exception, occurrence,
' or any other appointment.
Debug.Print "REFRESH ITEM COLLECTION"
Set oItems = Nothing
Set oItemNew = Nothing
Set oEx = Nothing
Set oEx2 = Nothing
Set oOccurrence = Nothing
Set oItemOriginal = Nothing
Set rPattern = Nothing
' Get new references to appointment items, including the appointment
' collection, individual appointments, and exceptions.
Set oItems = _
Outlook.Application.Session.GetDefaultFolder(olFolderCalendar).Items
Set oItemNew = oItems.Item(1)
' If no other add-ins have the same recurring appointment open,
' the new references reflect the current exception count.
Set oEx2 = oItemNew.GetRecurrencePattern().Exceptions
Debug.Print " New item exceptions: " & oEx2.Count
Debug.Print "RE-GET ORIGINAL"
Set oItemOriginal = oItems.Item(1)
Set oEx = oItemOriginal.GetRecurrencePattern().Exceptions
Debug.Print " Original item exceptions: " & oEx.Count
End Sub
示例
下面的 Visual Basic for Applications (VBA) 示例返回新约会。
Set myItem = Application.CreateItem(olAppointmentItem)
事件
方法
名称 |
---|
ClearRecurrencePattern |
Close |
Copy |
CopyTo |
删除 |
Display |
ForwardAsVcal |
GetConversation |
GetOrganizer |
GetRecurrencePattern |
Move |
PrintOut |
Respond |
Save |
SaveAs |
Send |
ShowCategoriesDialog |
属性
另请参阅
Outlook 对象模型引用如何:将约会 XML 数据导入到 Outlook 约会对象AppointmentItem 对象成员
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。