Outlook .Restrict方法不适用于Date [英] Outlook .Restrict method does not work with Date

查看:235
本文介绍了Outlook .Restrict方法不适用于Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Restrict()时似乎不接受日期值.

Restrict() does not seem to accept a date value when it is specified outside.

Public Sub EBS()
    Dim oMail As MailItem
    Dim sPath As String
    Dim dtDate As Date
    Dim dtRecDate As Date
    Dim sName As String

    Dim oNameSpace As Outlook.NameSpace
    Dim oInboxFolder As Outlook.Folder
    Dim oSentFolder As Outlook.Folder
    Dim i As Long

    Set oNameSpace = Application.GetNamespace("MAPI")
    Set oInboxFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
    Set oSentFolder = oNameSpace.GetDefaultFolder(olFolderSentMail)

    dtRecDate = DateAdd("d", -180, Now)

    Set setItems = oInboxFolder.Items
    Set RestrictedItems = setItems.Restrict("[ReceivedTime] < dtRecDate AND [MessageClass] = 'IPM.Note'")
    For i = RestrictedItems.Count To 1 Step -1
        Set oMail = RestrictedItems.item(i)
        sName = oMail.Subject
        dtDate = oMail.ReceivedTime
        sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "_hhnnss", vbUseSystemDayOfWeek, vbUseSystem) & "_" & sName & ".msg"
        sName = Left(sName, 256)
        sPath = "C:\ARCHIVE\OUTLOOK\Inbox\"
        Debug.Print dtRecDate
        oMail.SaveAs sPath & sName, olMSG
        oMail.Delete
    Next i
End Sub

例如,在使用"2014/06/13"代替dtRecDate时,此限制起作用.

The restriction works when, for example, '2014/06/13' is used instead of dtRecDate.

使用dtRecDate时,它不限制任何项目.

When dtRecDate is used, it does not restrict any item.

可以帮忙吗?

推荐答案

我在代码中看到以下过滤条件:

I see the following filter criteria in the code:

"[ReceivedTime] < dtRecDate AND [MessageClass] = 'IPM.Note'"

您不能在字符串中声明对象.它不会自动转换为字符串.您必须在代码中这样做,例如:

You can't declare object in the string. It will not be converted to string automatically. You have to do so in the code, for example:

"[ReceivedTime] < '" + Format(Date, "yyyy/mm/dd") +"' AND [MessageClass] = 'IPM.Note'"

限制方法在MSDN页面上具有以下示例:

The Restrict method has the following sample on the page in MSDN:

sFilter = "[LastModificationTime] > '" & Format("1/15/99 3:30pm", "ddddd h:nn AMPM") & "'"

这篇关于Outlook .Restrict方法不适用于Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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