根据发件人,主题和今天的日期搜索Outlook电子邮件 [英] Search for Outlook Email based on Sender, Subject, and Today's Date
问题描述
我应该每天都收到来自"BobSmith@company.com"
的主题为"Testing Protocol"
的电子邮件.
I am supposed to receive an email with the subject "Testing Protocol"
from "BobSmith@company.com"
every day.
有没有一种方法可以搜索我的Outlook收件箱,以确定当天是否有涉及该主题和该发件人的电子邮件?如果今天已收到或尚未收到,则希望在控件"的单元格A1中放置一个简单的是"或否".
Is there a way to search my Outlook Inbox to determine if an email has come through with that subject and that sender for the current day? Id like a simple "Yes" or "No" to be placed in cell A1 of "Control" if it has or has not been received today.
下面是我尝试使用以前的问题,没有运气独自提出的内容.
Below is what I have tried to come up with on my own using previous questions with no luck.
任何帮助将不胜感激. EmailSubject = "Testing Protocol"
Any help is greatly appreciated. EmailSubject = "Testing Protocol"
Private Sub Application_Reminder(ByVal Item As Object)
Dim EmailSubject As Range
Set EmailSubject = Sheets("Control").Range("EmailSubject")
If Item.Class = olTask Then
If InStr(Item.Subject, EmailSubject) > 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 = "BobSmith@company.com"
srchSubject = EmailSubject
Set Itms = Itms.Restrict("[SenderName] = "BobSmith@company.com" And
[Subject] = EmailSubject 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
推荐答案
对于srchSender来说,格式错误和组合过滤器对我来说需要一系列混乱的匹配引号.
Likely wrong format for srchSender and combining a filter, for me, requires a confusing sequence of matching quotes.
Private Sub ReminderUnreceivedMail()
Dim Itms As items
Dim srchSender As String
Dim srchSubject As String
Dim strFilterBuild As String
Dim ItmsBuild As items
Dim strFilter As String
Set Itms = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).items
Dim i As Long
For i = 1 To Itms.count
Debug.Print Itms(i).senderName
Next
srchSender = "what you see in senderName from the above"
srchSubject = "EmailSubject"
' If you cannot get the quotes right all at once, build the filter.
strFilterBuild = "[SenderName] = '" & srchSender & "'"
Debug.Print strFilterBuild
Set ItmsBuild = Itms.Restrict(strFilterBuild)
If ItmsBuild.count = 0 Then
MsgBox "No " & srchSender & " email."
GoTo ExitRoutine
End If
strFilterBuild = strFilterBuild & " And [Subject] = '" & srchSubject & "'"
Debug.Print strFilterBuild
Set ItmsBuild = Itms.Restrict(strFilterBuild)
If ItmsBuild.count = 0 Then
' This should find old mail
MsgBox "No " & srchSender & " email with subject " & srchSubject
GoTo ExitRoutine
End If
strFilterBuild = strFilterBuild & " And [SentOn] > '" & Format(Date, "yyyy-mm-dd") & "'"
Debug.Print strFilterBuild
Set ItmsBuild = Itms.Restrict(strFilterBuild)
If ItmsBuild.count = 0 Then
MsgBox "No " & srchSender & " email with subject " & srchSubject & " today"
GoTo ExitRoutine
End If
' This should match the final strFilterBuild to confirm it can be done all at once.
strFilter = "[SenderName] = '" & srchSender & "' And [Subject] = '" & srchSubject & "' And [SentOn] > '" & Format(Date, "yyyy-mm-dd") & "'"
Debug.Print strFilter
Set Itms = Itms.Restrict(strFilter)
If Itms.count = 0 Then
MsgBox "No " & srchSubject & " email on " & Format(Date, "yyyy-mm-dd")
End If
ExitRoutine:
Set Itms = Nothing
End Sub
这篇关于根据发件人,主题和今天的日期搜索Outlook电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!