如何在 Outlook 加载项中设置提醒事件
How to set reminder event in Outlook add-in
我正在尝试将一些工作 VBA 转换为 Outlook 加载项。我是 VSTO 的新手,也不是 Outlook 对象模型方面的专家,所以我在确定要在下面代码的 ThisAddin_Startup 部分中放置什么以有效地使提醒事件触发代码时遇到了一些麻烦在 Application_Reminder。我的目标是让任何提醒触发该代码,它只是查找提醒 window 并为其提供焦点。
Imports System.Windows.Forms
Public Class ThisAddin
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Dim WithEvents objOutlook As Outlook.Application
Private Sub ThisAddin_Startup() Handles Me.Startup
End Sub
Private Sub Application_Reminder(ByVal Item As Object)
Try
Dim ReminderWindowHWnd As Object
'Loop 25 times as FindWindowA needs exact title which varies according to number of reminder items...
Dim iReminderCount As Integer
For iReminderCount = 1 To 25
'Try two syntaxes...
ReminderWindowHWnd = FindWindowA(vbNullString, iReminderCount & " Reminder") : SetWindowPos(ReminderWindowHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
ReminderWindowHWnd = FindWindowA(vbNullString, iReminderCount & " Reminder(s)") : SetWindowPos(ReminderWindowHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Next
Exit Sub
Catch
MessageBox.Show(Err.Number & " - " & Err.Description) ' & " (iReminderCount = " & iReminderCount & ")")
End Try
End Sub
End Class
感谢任何帮助或指点!
事件缺少连接它的处理程序:
Private Sub Application_Reminder(Item As Object) Handles Application.Reminder
End Sub
您也可以删除 objOutlook 声明。 Application 对象是 ThisAddin class 的固有对象,不需要声明。您将在成员下拉列表中看到所有可用的应用程序事件;选择一个将为您创建事件处理程序。
我正在尝试将一些工作 VBA 转换为 Outlook 加载项。我是 VSTO 的新手,也不是 Outlook 对象模型方面的专家,所以我在确定要在下面代码的 ThisAddin_Startup 部分中放置什么以有效地使提醒事件触发代码时遇到了一些麻烦在 Application_Reminder。我的目标是让任何提醒触发该代码,它只是查找提醒 window 并为其提供焦点。
Imports System.Windows.Forms
Public Class ThisAddin
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Dim WithEvents objOutlook As Outlook.Application
Private Sub ThisAddin_Startup() Handles Me.Startup
End Sub
Private Sub Application_Reminder(ByVal Item As Object)
Try
Dim ReminderWindowHWnd As Object
'Loop 25 times as FindWindowA needs exact title which varies according to number of reminder items...
Dim iReminderCount As Integer
For iReminderCount = 1 To 25
'Try two syntaxes...
ReminderWindowHWnd = FindWindowA(vbNullString, iReminderCount & " Reminder") : SetWindowPos(ReminderWindowHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
ReminderWindowHWnd = FindWindowA(vbNullString, iReminderCount & " Reminder(s)") : SetWindowPos(ReminderWindowHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Next
Exit Sub
Catch
MessageBox.Show(Err.Number & " - " & Err.Description) ' & " (iReminderCount = " & iReminderCount & ")")
End Try
End Sub
End Class
感谢任何帮助或指点!
事件缺少连接它的处理程序:
Private Sub Application_Reminder(Item As Object) Handles Application.Reminder
End Sub
您也可以删除 objOutlook 声明。 Application 对象是 ThisAddin class 的固有对象,不需要声明。您将在成员下拉列表中看到所有可用的应用程序事件;选择一个将为您创建事件处理程序。