修改.Parent时,如何“保留”重复的AppointmentItem异常?

时间:2018-12-19 17:21:22

标签: vba outlook

这是我的第一篇文章!

我经常收到仅供参考的约会(不是我要去的约会)。他们弄乱了我的日历,隐藏了我需要参加的实际约会。

我写了一些代码将定期约会更改为整天。它将开始和结束时间附加到主题上,因此我仍然可以参考它。

Public Sub MakeSeriesAllDay()

Dim oAppt As AppointmentItem
Dim oApptParent As AppointmentItem

'Get the selected appointment
Set oAppt = Outlook.Application.ActiveExplorer.Selection.Item(1)

'Get the selected appointment's parent (series)
Set oApptParent = oAppt.Parent

'Append the appointment time into the parent subject (series)
oApptParent.Subject = oApptParent.Subject & ", " & Format(oApptParent.Start, "h:mm AM/PM") & "-" & Format(oApptParent.End, "h:mm AM/PM")
oApptParent.Save

'Change the appointment to start at midnight and be all day
oApptParent.GetRecurrencePattern.StartTime = #12:00:00 AM#
oApptParent.GetRecurrencePattern.Duration = 1440
oApptParent.Save

Set oAppt = Nothing
Set oApptParent = Nothing

End Sub

效果很好!问题是,修改AppointmentItem.Parent时,所有异常都将被覆盖。如何保留例外?或者更好的是,在更改父级之后,如何创建新的异常以反映旧的异常?

1 个答案:

答案 0 :(得分:0)

在使用定期约会项目时,应释放任何先前的参考,在访问或修改项目之前获取对定期约会项目的新参考,并在完成并保存更改后立即释放这些参考。

此做法适用于重复的AppointmentItem对象以及任何Exception或RecurrencePattern对象。要在Visual Basic for Applications(VBA)或Visual Basic中发布引用,请将现有对象设置为Nothing。在C#中,显式释放该对象的内存。

有关更多信息,请参考此链接:

Outlook RecurrencePattern.Exceptions.Count NOT updated after occurrence modified or deleted

Outlook VSTO - Save AppointmentItem Parent