Pergunta

I am using VBA to scan MAPIFolders for Items created before a certain date in order to move them to an archive PST. Normally Item.CreationDate is a good hook to scan for "old" Outlook items, but for calendar entries the "creation date" can be way before the "start date" so for calendar entries I rather want to use the latter.

My problem is with type MeetingItem which can be

  • an appointment where .GetAssociatedAppointment(False) seems to work fine
  • an acceptance msg to a received Appointment where .GetAssociatedAppointment(False) crashes

Any idea how to distinguish between the above cases to use the correct underlying object type in the Set statement?

Note: trying to inspect E in the debugger after it's been Set always results in "Outlook has encountered a problem and needs to close ..."

Private Function TimeOf(I As Object) As Date

Dim A As AppointmentItem
Dim M As MailItem
Dim E As MeetingItem
Dim T As TaskItem
Dim C As TaskRequestAcceptItem
Dim D As TaskRequestDeclineItem
Dim Q As TaskRequestItem
Dim U As TaskRequestUpdateItem

    Select Case TypeName(I)
    Case "AppointmentItem"
        Set A = I
        TimeOf = A.Start
        Set A = Nothing

    Case "MailItem"
        Set M = I
        TimeOf = M.ReceivedTime
        Set M = Nothing

    Case "MeetingItem"
        Set E = I
        Set A = E.GetAssociatedAppointment(False) ' doesn't work if item is a
                                                  ' response to an Appointment received
        TimeOf = A.Start                          ' <-- ERROR: Object variable ... not set
        Set E = Nothing
        Set A = Nothing

    Case "TaskItem"
        Set T = I
        TimeOf = T.Start
        Set T = Nothing

    Case "TaskRequestAcceptItem"
        Set C = I
        TimeOf = C.Start
        Set C = Nothing

    Case "TaskRequestDeclineItem"
        Set D = I
        TimeOf = D.Start
        Set D = Nothing

    Case "TaskRequestItem"
        Set Q = I
        TimeOf = Q.Start
        Set Q = Nothing

    Case "TaskRequestUpdateItem"
        Set U = I
        TimeOf = U.Start
        Set U = Nothing

    Case Else
        TimeOf = I.CreationTime
    End Select

End Function
Foi útil?

Solução

A request-type MeetingItem has a MessageClass of "IPM.Schedule.Meeting.Request". An acceptance-type of MeetingItem has a MessageClass of "IPM.Schedule.Meeting.Resp.Pos". Please refer here for more details on other MessageClass on Outlook 2003. I tested the following code in my Outlook 2007. It's working fine.

Private Function TimeOf(I As Object) As Date

Dim A As AppointmentItem
Dim M As MailItem
Dim E As MeetingItem
Dim T As TaskItem
Dim C As TaskRequestAcceptItem
Dim D As TaskRequestDeclineItem
Dim Q As TaskRequestItem
Dim U As TaskRequestUpdateItem

    Select Case TypeName(I)
    Case "AppointmentItem"
        Set A = I
        TimeOf = A.Start
        Set A = Nothing

    Case "MailItem"
        Set M = I
        TimeOf = M.ReceivedTime
        Set M = Nothing

    Case "MeetingItem"
        Set E = I
        If (E.MessageClass = "IPM.Schedule.Meeting.Request") Then
            ' Meeting Request
            Set A = E.GetAssociatedAppointment(False)
            TimeOf = A.Start
            Set A = Nothing
        Else
            ' Other MeetingItem
            TimeOf = E.ReceivedTime
        End If
        Set E = Nothing

    Case "TaskItem"
        Set T = I
        TimeOf = T.Start
        Set T = Nothing

    Case "TaskRequestAcceptItem"
        Set C = I
        TimeOf = C.Start
        Set C = Nothing

    Case "TaskRequestDeclineItem"
        Set D = I
        TimeOf = D.Start
        Set D = Nothing

    Case "TaskRequestItem"
        Set Q = I
        TimeOf = Q.Start
        Set Q = Nothing

    Case "TaskRequestUpdateItem"
        Set U = I
        TimeOf = U.Start
        Set U = Nothing

    Case Else
        TimeOf = I.CreationTime
    End Select

End Function
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top