使用限制方法获取收件人,主题和日期范围 [英] Use Restrict method to get recipient, subject and date range

查看:203
本文介绍了使用限制方法获取收件人,主题和日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了

'only works for name, not email address.
"@SQL=""urn:schemas:httpmail:displayto"" ci_phrasematch '%John Doe%'" 

'works great, failed when use AND. today was declared as string
"@SQL=""urn:schemas:httpmail:subject"" like '%" & emailSubject & "%'"

'works great, failed when use AND. today was declared as string
"[ReceivedTime] <= today" 

如何使用Item.Restrict一起过滤收件人电子邮件地址,主题和日期范围?

How can I use Item.Restrict to filter the recipient email address, subject and date range together?

推荐答案

以下是多个过滤器的示例

Option Explicit
Public Sub Example()
    Dim olNs As Outlook.NameSpace
    Dim TargetFolder As Outlook.MAPIFolder
    Dim Items As Outlook.Items
    Dim Item As Object
    Dim i As Long
    Dim Filter As String

    Set olNs = Application.Session
    If TargetFolder Is Nothing Then Set TargetFolder = ActiveExplorer.CurrentFolder
    Debug.Print TargetFolder.Name

    Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:datereceived" & _
                       Chr(34) & " >= '01/10/2018' And " & _
                       Chr(34) & "urn:schemas:httpmail:datereceived" & _
                       Chr(34) & " < '01/16/2018' And " & _
                       Chr(34) & "urn:schemas:httpmail:fromname" & _
                       Chr(34) & "Like '%0m3r 0m3r%'"

    Set Items = TargetFolder.Items.Restrict(Filter)
        Items.Sort "[ReceivedTime]"

    For i = Items.Count To 1 Step -1
        DoEvents
        If TypeOf Items(i) Is mailitem Then
            Set Item = Items(i)
            Debug.Print Item.Subject
            Debug.Print Item.ReceivedTime
        End If
    Next

End Sub


If TargetFolder Is Nothing Then Set TargetFolder = ActiveExplorer.CurrentFolder


If TargetFolder Is Nothing Then Set TargetFolder = ActiveExplorer.CurrentFolder

返回或设置MAPIFolder对象代表显示在资源管理器中的当前文件夹

或使用

Dim olNs As Outlook.NameSpace
Dim TargetFolder As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set TargetFolder = olNs.GetDefaultFolder(olFolderInbox)

使用主题行过滤

Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:datereceived" & _
                   Chr(34) & " >= '01/10/2018' And " & _
                   Chr(34) & "urn:schemas:httpmail:datereceived" & _
                   Chr(34) & " < '01/17/2018' And " & _
                   Chr(34) & "urn:schemas:httpmail:fromname" & _
                   Chr(34) & "Like '%0m3r 0m3r%' And " & _
                   Chr(34) & "urn:schemas:httpmail:subject" & _
                   Chr(34) & " Like '%Bla Bla%'"

这篇关于使用限制方法获取收件人,主题和日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆