【发布时间】:2022-01-02 02:56:10
【问题描述】:
您好,我有一个脚本可以循环遍历 Excel 表,以检查我是否收到了对已发送电子邮件的回复。该脚本在过去几个月中运行良好,但现在它在我的收件箱(outlook)中找不到(随机?)某些项目 我已经根据每封电子邮件中的 3 个标准构建了一个 DASL 过滤器。 我不确定这是否是引用我的 Outlook 文件夹的问题。在计算我的收件箱中受过滤器限制的项目时,items.count 返回 0,这是不正确的。 我知道我的 DASL 过滤器不是最好的,但我在字符串连接方面有点挣扎。我正在分享我可以成功找到的电子邮件的屏幕截图。用于查找该电子邮件的标准以红色突出显示。
Sub Search_InboxAndHighlight()
Dim myOlApp As New Outlook.Application
Dim objNamespace As Outlook.Namespace
'Dim objFolder As Outlook.MAPIFolder
Dim objFolder As Outlook.Folder
Dim filteredItems As Outlook.Items
Dim Sup_ENg_Number As Range
Dim OGDD_Programs As Range
Dim strFilter As String
Dim compName As String
Dim supNumber As String
Dim Program_type as String
'set a reference to cells we are going to loop through
Set OGDD_Programs = ActiveSheet.Range("A2", "A" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
Set objNamespace = myOlApp.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set fol = objNamespace.Folders("myEmailaddress").Folders("Sent Items")
"loop through cells on activesheet
For Each Sup_ENg_Number In OGDD_Programs
supNumber = "'" & Sup_ENg_Number.Value & "'"
compName = Sup_ENg_Number.Offset(, 1).Value
compName = "'" & compName & "'"
Program_type = "'" & Sup_ENg_Number..Offset(, 3)Value & "'"
' filter to search sup_eng_number and company name in body of the eemail
strFilter = "@SQL=""urn:schemas:httpmail:textdescription"" ci_phrasematch " & supNumber
strFilter = strFilter & " AND "
strFilter = strFilter & """urn:schemas:httpmail:textdescription"" ci_phrasematch " & compName
strFilter = strFilter & " AND "
strFilter = strFilter & """urn:schemas:httpmail:textdescription"" ci_phrasematch " & Program_type
'restrict items to lookup to be only of the filter "strFilter"
Set filteredItems = objFolder.Items.Restrict(strFilter)
Set SentFilteredItems = fol.Items.Restrict(strFilter)
If filteredItems.Count = 0 AND SentFilteredItems.Count = 0 then
Sup_ENg_Number.Interior.Color = vbRed
end if
Next Sup_ENg_Number
MsgBox "Completed!"
'If the subject isn't found:
If Not Found Then
'NoResults.Show
Else
'Debug.Print "Found " & filteredItems.Count & " items."
End If
Application.ScreenUpdating = True
'myOlApp.Quit
Set myOlApp = Nothing
End Sub
【问题讨论】:
-
发布应该与您的 DASL 过滤器匹配的电子邮件图像。
Program_type未定义。 -
我手动重写了上面的代码,是的,我在真实代码中定义了 Program_type,不幸的是我无法显示屏幕截图,因为它包含敏感信息..我昨天玩过并删除了 Program_Type 标准,filteredItems.Count返回一些东西,但我需要使用所有 3 个标准来找到正确的电子邮件
-
创建一个仅用于测试的虚拟邮件并发布它的图像。我尝试使用
View->View Settings->Filter->Advanced->Field->Frequently-used-fields->Message创建 DASL 过滤器以匹配您的过滤器,但我没有得到相同的过滤器!您是如何创建它们的? -
我按照脚本所示创建了它们,我将尝试创建一个虚拟电子邮件