如何在Outlook加载项中设置提醒事件

时间:2017-04-19 16:19:09

标签: visual-studio-2015 outlook vsto outlook-addin

我正在尝试将一些正在运行的VBA转换为Outlook加载项。我是VSTO的新手,也没有关于Outlook对象模型的专家,所以我在下面代码的ThisAddin_Startup部分中确切地放置了什么,以便有效地使提醒事件触发Application_Reminder中的代码。我的目标是让任何提醒点火代码,它只是寻找提醒窗口并给予焦点。

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

感谢您的帮助或指示!

1 个答案:

答案 0 :(得分:1)

事件缺少连接它的处理程序:

Private Sub Application_Reminder(Item As Object) Handles Application.Reminder

End Sub

你也可以摆脱objOutlook声明。 Application对象是ThisAddin类的固有对象,不需要声明。您将在成员下拉列表中看到所有可用的应用程序事件;选择一个将为您创建事件处理程序。