约会删除失败,可能是由于AppointmentItem为空?

时间:2014-01-13 14:41:10

标签: outlook-vba

Sub AutoCancel(ByRef Item As Outlook.MeetingItem)

  Dim strID As String
  Dim olNS As Outlook.NameSpace
  Dim oMeetingItem As Outlook.MeetingItem
  Dim oResponse As Outlook.MeetingItem
  Dim oAppointment As Outlook.AppointmentItem

  strID = Item.EntryID

  Set olNS = Application.GetNamespace("MAPI")
  Set oMeetingItem = olNS.GetItemFromID(strID)
  Set oAppointment = oMeetingItem.GetAssociatedAppointment(False)

 oAppointment.Delete

  Set oAppointment = Nothing
  Set oMeetingItem = Nothing
  Set olNS = Nothing

End Sub

我有大量订阅/取消的电子邮件,我希望自动接受或取消,然后从收件箱中删除。 accept方法似乎有效,但是此方法会针对指向oAppointment.Delete行的每次取消向用户发送调试报告。 我的想法是,在oMeetingItem.GetAssociatedAppointment返回null的某些情况下,它出错了,因此它没有任何内容可以删除。这只是一种预感。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

是的,如果您将false传递给GetAssociatedAppointment,它将创建约会(如果它尚不存在)。