按日期限制Outlook项目 [英] Restrict Outlook Items by Date

查看:145
本文介绍了按日期限制Outlook项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Outlook宏,可以按日期过滤电子邮件对象并根据数组返回项目.

I have an Outlook macro that filters email objects by date and returns items based on an array.

今天的过滤器如下:

sfilter = "[ReceivedTime]>=""&Date()12:00am&"""
Set myItems = myNewFolder.Items.Restrict(sfilter)

sFilter是一个字符串,它按预期返回今天的项目.

sFilter is a string and this returns the items for today as intended.

我正在尝试过滤昨天收到的电子邮件.

I am trying to filter to emails received yesterday.

以下是我的尝试.

sfilter = "[ReceivedTime]>=""&Date(-1) 12:00am&"" AND [ReceivedTime]<= ""&Date() 12:00am&"" "
tfilter = Format(DateAdd("d", -1, Date), "mm/dd/yyyy")
rFilter = Format(DateAdd("d", 0, Date), "mm/dd/yyyy")

我打算将tFilter和rFilter用作sFilter的上限和下限.

I intended to use the tFilter and rFilter as the upper and lower bound for sFilter.

我在MSDN站点上查看了具有功能信息后,尝试使用DateAdd方法,但是没有返回昨天的项目.

I tried to use the DateAdd method after looking on the MSDN site with the function information but that did not return yesterday's items.

我尝试了针对此问题提供的解决方案( Outlook.使用日期).

I tried the solution offered on this question (Outlook .Restrict method does not work with Date).

带有date(-1)的方法不能与date一起使用.根据MSDN站点,逻辑运算符应该起作用.

The method with date(-1) did not work in tandem with date. According to the MSDN site logical operators should work.

注意:引用的下面三个示例进行编译,并且不返回任何错误.

Note: The lower three examples cited compile and do not return any errors.

推荐答案

您可以找到带有两个单独限制的昨天的邮件.

You can find yesterday's mail with two separate Restricts.

Private Sub EmailYesterday()

Dim oOlInb As Folder
Dim oOlItm As Object

Dim oOlResults As Object
Dim i As Long

Dim sFilter As String
Dim sFilter2 As String

Set oOlInb = Session.GetDefaultFolder(olFolderInbox)

'Filter recent - Lower Bound of the range
sFilter = "[ReceivedTime]>'" & format(Date - 1, "DDDDD HH:NN") & "'"

Debug.Print vbCr & sFilter
Set oOlResults = oOlInb.Items.Restrict(sFilter)
Debug.Print oOlResults.count & " items."

If oOlResults.count > 0 Then
    For i = 1 To oOlResults.count
        Set oOlItm = oOlResults(i)
        Debug.Print oOlItm.Subject & " - " & oOlItm.ReceivedTime
    Next i
End If

' Filter range - Upper Bound
sFilter2 = "[ReceivedTime]<'" & format(Date, "DDDDD HH:NN") & "'"

Debug.Print vbCr & sFilter; " AND " & sFilter2

Set oOlResults = oOlResults.Restrict(sFilter2)   ' Restrict the Lower Bound result
Debug.Print oOlResults.count & " items."

If oOlResults.count > 0 Then
    For i = 1 To oOlResults.count
        Set oOlItm = oOlResults(i)
        Debug.Print oOlItm.Subject & " - " & oOlItm.ReceivedTime
    Next i
End If

ExitRoutine:
    Set oOlInb = Nothing
    Set oOlResults = Nothing
    Debug.Print "Done."

End Sub

这篇关于按日期限制Outlook项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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