用户保存约会后的操作

时间:2019-07-27 14:43:52

标签: vb.net vsto outlook-addin

在用户使用Outlook 2016保存约会后,我需要显示一条简单消息(即“确定”)。我正在考虑增强现有的(VB.NET)VSTO Outlook加载项,该加载项会挂在AppointmentItem AfterWrite上加载项启动中的事件; 到目前为止,我想出的是:

Private WithEvents Inspectors As Outlook.Inspectors

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    Inspectors = Me.Application.Inspectors
End Sub

Private WithEvents apptItem As Outlook.AppointmentItem

Private Sub objinspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles Inspectors.NewInspector
    Dim apptItem As Outlook.AppointmentItem = TryCast(Inspector.CurrentItem, Outlook.AppointmentItem)
    If Not (apptItem Is Nothing) Then
        MessageBox.Show("OK")
        apptItem = Inspector.CurrentItem
    End If
End Sub

这实际上是在我打开约会窗口时显示的消息(“确定”),我想要的是仅在创建/保存/写入约会后才显示该消息(用户基本上单击“保存并关闭”)。你有一个想法怎么做吗?

最新编辑: 我通过使用以下代码进行管理:

Private WithEvents Inspectors As Outlook.Inspectors

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        Inspectors = Me.Application.Inspectors
        AddHandler Inspectors.NewInspector, AddressOf Me.objinspectors_NewInspector
    End Sub

    Public WithEvents apptItem As Outlook.AppointmentItem

    Private Sub objinspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector)
        Dim apptItem As Outlook.AppointmentItem = TryCast(Inspector.CurrentItem, Outlook.AppointmentItem)
        If Not (apptItem Is Nothing) Then
            If apptItem.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olNonMeeting Then
                'only for the AppointmentItem Object, we hook on the AfterWrite event to process what we want after the Appointment has been saved.
                AddHandler apptItem.AfterWrite, AddressOf AppointmentSaved
            End If
        End If
    End Sub

    Public Sub AppointmentSaved() Handles apptItem.AfterWrite
        MessageBox.Show("Appointment saved")
    End Sub

在保存约会时显示一条消息。下一步将是在显示消息时访问“约会对象”属性。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您需要在apptItem变量上设置事件处理程序。声明apptItem_AfterWrite事件处理程序。 另外请记住,由于您可以有多个未清项目,因此您确实需要一个项目列表,而不是一个AppointmeentItem类型变量。

相关问题