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

时间:2019-03-07 16:34:39

标签: vba outlook dismiss reminders

我想在特定时间在Outlook中运行宏,因此我正在使用Outlook提醒进行此操作。我已经编写了以下代码,该代码成功运行了宏,但是在完成If语句后,它会弹出我不需要查看的提醒,因此需要关闭/关闭它。

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

请有人帮我建议如何取消提醒?

1 个答案:

答案 0 :(得分:1)

好的,我想我已经知道了-以下内容似乎可以正常使用,所有代码都在“ 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