如何通过 Outlook 关闭或取消 Outlook 提醒 VBA

How to close or dismiss an Outlook Reminder via Outlook VBA

我想在特定时间在 Outlook 中 运行 宏,所以我正在使用 Outlook 提醒来执行此操作。我已经编写了下面的代码,它成功地 运行s 宏但是在完成 If 语句之后,它会弹出我不需要看到的提醒,因此需要 close/dismiss它。

Public Sub Application_Reminder(ByVal Item As Object)
If Item.Subject = "Refresh Data Test" Then
    Call RunExcelMacros.TestRun
End If
End Sub

有人可以帮助我建议如何取消提醒吗?

好的,我想我明白了 - 下面的代码似乎有效,所有代码都在 "ThisOutlookSession" 模块中设置:

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