Outlook .items.restrict使用两个filter

我正在使用一个脚本来打开电子邮件并下载附件。 现在,我可以select在最近的电子邮件中下载最新的附件:

Sub CTEmailAttDownload() Const olFolderInbox As Integer = 6 '~~> Path for the attachment Const AttachmentPath As String = "C:\TEMP\TestExcel" Dim oOlAp As Object Dim oOlns As Object Dim oOlInb As Object Dim oOlItm As Object Dim oOlAtch As Object Dim oOlResults As Object Dim x As Long Dim NewFileName As String NewFileName = "Daily Tracker " & Format(Now, "dd-MM-yyyy") 'You can only have a single instance of Outlook, so if it's already open 'this will be the same as GetObject, otherwise it will open Outlook. Set oOlAp = CreateObject("Outlook.Application") Set oOlns = oOlAp.GetNamespace("MAPI") Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox) 'No point searching the whole Inbox - just since yesterday. Set oOlResults = oOlInb.Items.Restrict("[ReceivedTime]>'" & Format(Date - 1, "DDDDD HH:NN") & "'") 'If you have more than a single attachment they'll all overwrite each other. 'x will update the filename. x = 1 For Each oOlItm In oOlResults If oOlItm.Attachments.Count > 0 Then For Each oOlAtch In oOlItm.Attachments If GetExt(oOlAtch.FileName) = "xlsx" Then oOlAtch.SaveAsFile AttachmentPath & "\" & NewFileName & ".xlsx" End If x = x + 1 Next oOlAtch End If Next oOlItm End Sub '---------------------------------------------------------------------- ' GetExt ' ' Returns the extension of a file. '---------------------------------------------------------------------- Public Function GetExt(FileName As String) As String Dim mFSO As Object Set mFSO = CreateObject("Scripting.FileSystemObject") GetExt = mFSO.GetExtensionName(FileName) End Function 

通过使用'[Subject] ='我可以按主题下载。

我的问题是,我怎样才能把这两个filter,所以我可以按主题和ReceivedTime过滤?

我试着把它们绑定在一起&+ ,到目前为止我还没有成功。

 @SQL=(Subject LIKE '%blah%') AND (ReceivedTime > '01/02/2015') 

即使只有一个限制,也很难获得语法。 正如斯科特·霍尔茨曼(Scott Holtzman)的评论所指出的那样,如果你单独了解每个filter,你可以过滤两次

 Option Explicit Sub CTEmailAttDownload() Const olFolderInbox As Integer = 6 '~~> Path for the attachment Const AttachmentPath As String = "C:\TEMP\TestExcel" Dim oOlAp As Object Dim oOlns As Object Dim oOlInb As Object Dim oOlItm As Object Dim oOlAtch As Object Dim oOlResults As Object Dim oOlSubjectResults As Object Dim strFilter As String Dim i As Long Dim x As Long Dim NewFileName As String NewFileName = "Daily Tracker " & format(Now, "dd-MM-yyyy") 'You can only have a single instance of Outlook, so if it's already open 'this will be the same as GetObject, otherwise it will open Outlook. Set oOlAp = CreateObject("Outlook.Application") Set oOlns = oOlAp.GetNamespace("MAPI") Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox) 'No point searching the whole Inbox - just since yesterday. Set oOlResults = oOlInb.Items.Restrict("[ReceivedTime]>'" & format(Date - 1, "DDDDD HH:NN") & "'") strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%test%'" Set oOlSubjectResults = oOlResults.Restrict(strFilter) If oOlSubjectResults.count = 0 Then Debug.Print "No emails found with applicable subject" Else 'If you have more than a single attachment they'll all overwrite each other. 'x will update the filename. x = 1 For i = 1 To oOlSubjectResults.count Set oOlItm = oOlSubjectResults(i) If oOlItm.Attachments.count > 0 Then Debug.Print oOlItm.Subject For Each oOlAtch In oOlItm.Attachments Debug.Print oOlAtch.DisplayName If GetExt(oOlAtch.FileName) = "xlsx" Then oOlAtch.SaveAsFile AttachmentPath & "\" & NewFileName & ".xlsx" End If x = x + 1 Next oOlAtch End If Next i End If ExitRoutine: Set oOlAp = Nothing Set oOlns = Nothing Set oOlInb = Nothing Set oOlResults = Nothing Set oOlSubjectResults = Nothing End Sub