I want to run a Macro in Outlook at a certain time and so I'm using the Outlook Reminders to do it. I have written the below code, which successfully runs the Macro but after it has finished the If statement, it then pops up the reminder which I don't need to see and so therefore need to close/dismiss it.
Public Sub Application_Reminder(ByVal Item As Object)
If Item.Subject = "Refresh Data Test" Then
Call RunExcelMacros.TestRun
End If
End Sub
Please can someone help suggest how I can dismiss the reminder?
Okay, I think I've got it - the below seems to work, all code is setup in the "ThisOutlookSession" Module:
Private WithEvents OutlookReminders As Outlook.Reminders
Public Sub Application_Reminder(ByVal Item As Object)
Set OutlookReminders = Outlook.Reminders
If Item.Subject = "Refresh Data Test" Then
Call RunExcelMacros.TestRun
End If
End Sub
Private Sub OutlookReminders_BeforeReminderShow(Cancel As Boolean)
Dim OutlookReminder As Reminder
'After the "Application_Reminder" has run it will then run this code straight after which stops the reminder from actually popping up
For Each OutlookReminder In OutlookReminders
If OutlookReminder.Caption = "Refresh Data Test" Then
If OutlookReminder.IsVisible Then
OutlookReminder.Dismiss
Cancel = True
End If
Exit For
End If
Next OutlookReminder
End Sub