且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查是否未收到电子邮件

更新时间:2021-08-04 22:02:04

评论中指出的方法.

Outlook VBA - 每半小时运行一次代码

展望VBA - 使用 Outlook 2010 64 位每半小时运行一次代码

一个可能更简单的替代方案.设置带有提醒的重复任务.

A possibly simpler alternative. Set a recurring task with a reminder.

在这个OutlookSession中

In ThisOutlookSession

Private Sub Application_Reminder(ByVal Item As Object)

If Item.Class = olTask Then
    If InStr(Item.Subject, "subject") > 0 Then
        ReminderUnreceivedMail
    End If
End If

End Sub

Sub ReminderUnreceivedMail()

Dim Itms As Items
Dim srchSender As String
Dim srchSubject As String

Set Itms = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
srchSender = "sender"
srchSubject = "subject"

Set Itms = Itms.Restrict("[SenderName] = 'sender' And [Subject] = 'subject' And [SentOn] > '" & Format(Date, "yyyy-mm-dd") & "'")

If Itms.count = 0 Then
    MsgBox "No " & srchSubject & " email on " & Format(Date, "yyyy-mm-dd")
End If

Set Itms = Nothing

End Sub