VSTO Outlook 约会事件 (VB.NET)
VSTO Outlook Appointment Event (VB.NET)
使用 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.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
但是 none 以下事件有效,实际上这一行 (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 无效,因为当您使用事件声明对象时,不会自动添加事件处理程序。例如,这里是 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
关键字以指定它处理特定事件。有关详细信息,请参阅 Handles。
AddHandler appt.PropertyChange, AddressOf myappt_PropertyChange
使用 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.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
但是 none 以下事件有效,实际上这一行 (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 无效,因为当您使用事件声明对象时,不会自动添加事件处理程序。例如,这里是 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
关键字以指定它处理特定事件。有关详细信息,请参阅 Handles。
AddHandler appt.PropertyChange, AddressOf myappt_PropertyChange