NewInspector事件仅适用一次

时间:2017-05-19 12:54:53

标签: vba outlook outlook-vba

我在run a macro when creating new appointment in outlook

的ThisOutlookSession模块中有代码
Private WithEvents appt As AppointmentItem
Private WithEvents objinspectors As Outlook.Inspectors

Private Sub Application_Startup()
    Set objinspectors = Application.Inspectors
End Sub

Private Sub objinspectors_NewInspector(ByVal Inspector As Inspector)
    If TypeName(Inspector.CurrentItem) = "AppointmentItem" Then
        Set appt = Inspector.CurrentItem
    End If
End Sub

Private Sub appt_Write(ByVal Item As Object, Cancel As Boolean)
    '---- ect
end sub

appt_Write适用于我创建或修改的第一个约会。如果我创建第二个约会没有任何反应。

我发现sub objinspectors_NewInspector不再启动了。

我的代码中没有END命令。要再次运行代码,我必须启动Application_Startup。

我应该怎么做才能让宏一直工作?

1 个答案:

答案 0 :(得分:0)

每次通过

重新运行与Application_Startup()相同的代码
Private Sub appt_Write(ByVal Item As Object, Cancel As Boolean)
    '---- etc

    Set objinspectors = Application.Inspectors 'add this line ... see what happens
End Sub