Vba 按邮件列表上的ReceivedTime设置限制
我试图阅读今天才收到的邮件。下面是我限制但其抛出条件无效错误的代码。当我给出一个类似于Vba 按邮件列表上的ReceivedTime设置限制,vba,outlook,Vba,Outlook,我试图阅读今天才收到的邮件。下面是我限制但其抛出条件无效错误的代码。当我给出一个类似于unread=True的条件时,同样可以正常工作 Set myItems = myItems.Restrict("DateValue[ReceivedTime]='" & Format(DateValue(Now),"ddddd h:nn AMPM") & "'") 请在这方面帮助我。我发现至少有两个问题 您有“DateValue[ReceivedTime]”而不是“[ReceivedTime
unread=True
的条件时,同样可以正常工作
Set myItems = myItems.Restrict("DateValue[ReceivedTime]='" & Format(DateValue(Now),"ddddd h:nn AMPM") & "'")
请在这方面帮助我。我发现至少有两个问题
Sub RestrictByDate()
Dim FmtToday As String
Dim FldrInbox As Folder
Dim MailItemsToday As Items
Dim MailItemCrnt As MailItem
FmtToday = Format(DateValue(Now()), "ddddd h:nn AMPM")
' #### Replace "xxxx" with the name of the store containing the target Inbox
Set FldrInbox = Session.Folders("xxxx").Folders("Inbox")
Set MailItemsToday = FldrInbox.Items.Restrict("[ReceivedTime] > '" & FmtToday & "'")
Debug.Print "Number of emails received today=" & MailItemsToday.Count
For Each MailItemCrnt In MailItemsToday
With MailItemCrnt
Debug.Print .ReceivedTime & " " & .Subject
End With
Next
End Sub
谢谢你的回复,托尼。它确实帮助“将FmtToday设置为字符串FmtToday=Format(DateValue(Now()),“ddddd h:nn AMPM”)设置mailitestoday=FldrInbox.Items.Restrict(“[ReceivedTime]>””&FmtToday&“”)。我已经用这个修改了我的代码,它成功了。