Home > OS >  Outlook VSTO App - VB - BeforeReminderShow event not working
Outlook VSTO App - VB - BeforeReminderShow event not working

Time:03-12

I am performing some actions on Outlook's Application_Reminder event. After actions are done, I want to dismiss/remove the reminder (as not to run actions later unintentionally due to second reminder of appointment) with the codes below but breakpoints not hit in _BeforeReminderShow event, not fired. Any idea on what I am missing ?

    Imports System.Windows.Forms
    Imports System.Windows.Interop
    Imports Microsoft.Office.Interop.Outlook
    Imports Microsoft.Office.Tools
    Imports System.IO
    Imports System.Text

    Public Class ThisAddIn
        Private WithEvents ObjReminders As Reminders

        Private Sub ObjReminders_BeforeReminderShow(Cancel As Boolean)

            For Each objRem In ObjReminders
                If objRem.Caption = "testing" Then
                    If objRem.IsVisible Then
                        objRem.Dismiss
                        Cancel = True
                    End If
                    Exit For
                End If
            Next objRem
        End Sub

I also tried the version below after eugene's reply but it also does not reach to BeforeReminderShow event.

Public Class ThisAddIn
    Private WithEvents OlRemind As Microsoft.Office.Interop.Outlook.Reminders

    Private Sub OlRemind_BeforeReminderShow(Cancel As Boolean)
        OlRemind = Application.Reminders
        For Each objRem In OlRemind
            If objRem.Caption = "testing" Then
                If objRem.IsVisible Then
                    objRem.Dismiss
                    Cancel = True
                End If
                Exit For
            End If
        Next objRem

    End Sub

CodePudding user response:

You need to initialize the source object, declaring the reminder object is not enough. So, anywhere in the code you could run the following command:

Set ObjReminders = Application.Reminders

Your code could look in the following way:

' declare this object withEvents throwing all the events
Private WithEvents olRemind As Outlook.Reminders

' run somewhere to initialize the source object
Set olRemind = Application.Reminders

Private Sub olRemind_BeforeReminderShow(Cancel As Boolean)

    For Each objRem In olRemind
        If objRem.Caption = "TESTING" Then
            If objRem.IsVisible Then
                objRem.Dismiss
                Cancel = True
            End If
            Exit For
        End If
    Next objRem

End Sub

CodePudding user response:

You still need to initialize the olRemind object when your addin starts up and you need to either add Handles olRemind.BeforeReminderShow or use AddHandler.

See https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/how-to-call-an-event-handler

  • Related