Reputation: 89
I'm trying to convert some working VBA into an Outlook add-in. I'm new to VSTO, and also no expert on the Outlook object model, so I'm having some trouble with what exactly to put in the ThisAddin_Startup portion of the code below to effectively make a reminder event fire the code in Application_Reminder. My goal is to have any reminder fire that code, which simply looks for the reminder window and gives it the focus.
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
Thanks for any assistance or pointers!
Upvotes: 0
Views: 311
Reputation: 5834
The event is missing the handler that wires it up:
Private Sub Application_Reminder(Item As Object) Handles Application.Reminder
End Sub
You can also get rid of the objOutlook declaration. The Application object is intrinsic to the ThisAddin class and doesn't need to be declared. You'll see all the available Application events in the member dropdown; picking one will create the event handler for you.
Upvotes: 1