触发发送时获取AppointmentItem数据

时间:2019-04-12 20:52:21

标签: vba outlook outlook-vba

我发送Outlook 2016约会时,使用以下触发VBA代码:

Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

如何显示特定于“ AppointmentItem”类型的数据?

我希望有一个消息框“您想在学校谈论计算机”,
但出现运行时错误“ 438”。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim prompt As String
    prompt = "Do you want to talk about " & Item.Subject    'Works
    prompt = prompt & " at " & Item.Location                'Error
    If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
        Cancel = True
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

如果您发送会议请求,则发送的项目本身是olMeetingRequest而不是olAppoinmentItem

您可以通过GetAssociatedAppointment

解决相应的约会项目
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objAppointment As AppointmentItem
    If Item.Class = olMeetingRequest Then
        Set objAppointment = Item.GetAssociatedAppointment(False)
        Debug.Print objAppointment.Subject
        Debug.Print objAppointment.Location
    End If
End Sub