2017-04-19 103 views
0

我試圖將一些可用的VBA轉換爲Outlook加載項。我是VSTO的新手,也沒有Outlook對象模型方面的專家,所以我在下面的代碼的ThisAddin_Startup部分放置了什麼,以便有效地使提醒事件觸發Application_Reminder中的代碼時遇到了一些問題。我的目標是讓任何提醒激發代碼,它只是查找提醒窗口並將其提供給焦點。如何在Outlook加載項中設置提醒事件

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

事件缺少處理程序,電線起來:

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

End Sub 

您也可以擺脫objOutlook聲明。 Application對象是ThisAddin類的內部對象,不需要聲明。您將在成員下拉菜單中看到所有可用的應用程序事件;選擇一個將爲您創建事件處理程序。

+0

我知道這會很簡單;那工作。謝謝,埃裏克! – Ryk

相關問題