VSTO Outlook约会事件(VB.NET)
使用Outlook VSTO[VB.NET]VISUAL Studio 2019时VSTO Outlook约会事件(VB.NET),vb.net,vsto,outlook-addin,Vb.net,Vsto,Outlook Addin,使用Outlook VSTO[VB.NET]VISUAL Studio 2019时 Imports Microsoft.Office.Tools Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.Outlook Private WithEvents inspectors As Outlook.Inspectors Private WithEvents myappt As Outlook.AppointmentIt
Imports Microsoft.Office.Tools
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook
Private WithEvents inspectors As Outlook.Inspectors
Private WithEvents myappt As Outlook.AppointmentItem
Private Sub ThisAddIn_Startup() Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
If TypeOf Inspector.CurrentItem Is Outlook.AppointmentItem Or TypeOf Inspector.CurrentItem Is Outlook.MeetingItem Then
myappt = Inspector.CurrentItem
End If
End Sub
但是下面的事件都不起作用,实际上这一行(myappt=Inspector.CurrentItem)在打开新约会时会被点击
Private Sub myappt_PropertyChange(ByVal Name As String)
MsgBox(Name)
End Sub
Private Sub myappt_Close(Cancel As Boolean)
MsgBox("Hi")
End Sub
实际上,每当约会时间发生变化时,我都想捕捉该事件并执行一些操作
属性更改是否缺少某些事件处理程序该代码对VBA有效,但对VB.NET无效,在VB.NET中,在声明包含事件的对象时不会自动添加事件处理程序。例如,以下是VBA中的代码:
Public WithEvents myItem As Outlook.AppointmentItem
Sub Initialize_handler()
Set myItem = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items("Status Meeting")
End Sub
Private Sub myItem_PropertyChange(ByVal Name As String)
Select Case Name
Case "ReminderSet"
MsgBox "You may not remove a reminder on this item."
myItem.ReminderSet = True
Case Else
End Select
End Sub
在VB.Net中,您需要使用AddHandler
和RemoveHandler
语句,这些语句允许您在程序执行期间随时启动和停止事件处理。Handles
关键字和AddHandler
语句都允许您指定特定的过程处理特定的事件,但它们有区别。AddHandler
语句在运行时将过程连接到事件。定义过程时,请使用Handles
关键字指定它处理特定事件。有关详细信息,请参阅
您是否收到错误或事件未触发?如何添加事件?得到的答案缺少处理程序事件
myappt=DirectCast(Inspector.CurrentItem,Outlook.AppointmentItem)AddHandler myappt.PropertyChange,AddressOf myappt\u PropertyChange
AddHandler appt.PropertyChange, AddressOf myappt_PropertyChange