【发布时间】:2018-07-20 21:23:21
【问题描述】:
给定的代码成功运行。它在 Outlook 已发送邮件文件夹中搜索电子邮件主题。搜索基于特定时间段内的特定日期进行。例如,下面的代码查找 2018 年 7 月 20 日上午 12:00 到晚上 11:59 之间发送的电子邮件标题“周五发送的测试电子邮件”。
除了我现有的搜索条件外,我如何过滤发送给特定用户的电子邮件。我想检查 [To] 字段。如果 [To] 有收件人 x@email.com、y@email.com 或 z@email.com,则不要返回搜索结果。如果 [To] 部分没有以下任一电子邮件,则搜索应返回“Yes. Email found”:x@email.com、y@email.com 或 z@email.com。
Public Function is_email_sent()
Dim olApp As Object
Dim olNs As Object
Dim olFldr As Object
Dim olItms As Object
Dim objItem As Object
On Error Resume Next
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.Folders("myemail@example.com").Folders("Sent Items")
Set olItms = olFldr.Items
Set objItem = olItms.Restrict("[Subject] = ""Test Email Sent on Friday"" And [SentOn] >= ""7/20/2018 12:00 AM"" AND [SentOn] <= ""7/20/2018 11:59 PM""")
If objItem.Count = 0 Then
MsgBox "No. Email not found"
Else
MsgBox "Yes. Email found"
End If
Set olApp = Nothing
Set olNs = Nothing
Set olFldr = Nothing
Set olItms = Nothing
Set objItem = Nothing
End Function
【问题讨论】:
-
您已经知道如何过滤,因为它在您的代码中。将附加条件添加到过滤器以排除电子邮件地址。
-
@Ken White 在我的过滤器中添加 [To] = '######' OR [To] = '######' 没有任何作用。
标签: excel vba ms-access outlook