在Outlook日历中捕获创建事件

时间:2016-05-19 07:33:45

标签: vba events outlook calendar

我正在尝试捕获事件,当一个人在Outlook的工作周视图中直接创建新的日历条目时(使用"新约会"按钮)

通过" New Appointment"捕捉事件是什么?使用此代码的按钮:

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

在周视图中直接创建活动时,不会调用newInspector子。

这方面的正确方法是什么?

感谢。

2 个答案:

答案 0 :(得分:0)

glob返回的日历文件夹中使用for file in glob.glob('G:\\*\\*.mp3"): print(file) 事件。

答案 1 :(得分:0)

Dimitry,谢谢。有了这个,我发现了以下内容:

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

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