简体   繁体   English

在Outlook日历中捕获创建事件

[英]Capture create event in Outlook calendar

I am trying to capture the event, when one is creating a new calendar entry directly within Outlook's work week view ( not using "New Appointment" button). 我正在尝试捕获事件,这是在Outlook的工作周视图中直接创建一个新的日历项时( 使用“新约会”按钮)。

What's working is to capture the event fired through the "New Appointment" button with this code: 工作原理是使用以下代码捕获通过“新约会”按钮触发的事件:

Dim WithEvents colInsp As Outlook.Inspectors
Dim WithEvents oAppt As Outlook.AppointmentItem

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

Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
    If Inspector.CurrentItem.Class = olAppointment Then
       Set oAppt = Inspector.CurrentItem
    End If
End Sub

Private Sub oAppt_Write(cancel As Boolean)
' Do something
End Sub

The newInspector sub doesn't get called when creating an event directly in the weeks view. 直接在周视图中创建事件时,不会调用newInspector子。

What is the correct approach for this? 正确的方法是什么?

Thanks. 谢谢。

使用从Namespace.GetDefaultFolder(olFolderCalendar)返回的Calendar文件夹上的Items.ItemAdd事件。

Dimitry, thank you. Dimitry,谢谢。 With this I found the following: 有了这个,我发现了以下几点:

Private WithEvents colItems As Outlook.Items

Private Sub Application_Startup()
    Dim oFolder As Outlook.MAPIFolder
    Dim oNS As Outlook.NameSpace

    Set oNS = Application.GetNamespace("MAPI")
    Set oFolder = oNS.GetDefaultFolder(olFolderCalendar)
    Set colItems = oFolder.Items

    Set oNS = Nothing
    Set oFolder = Nothing
End Sub

Sub colItems_ItemAdd(ByVal Item As Object)
    ' Do what's needed
End Sub

Source: http://microsoft.public.office.developer.outlook.vba.narkive.com/6zlusiPe/new-calendar-item-is-created 来源: http//microsoft.public.office.developer.outlook.vba.narkive.com/6zlusiPe/new-calendar-item-is-created

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM