我看到至少有兩個問題。
- 您有「DateValue [ReceivedTime]」而不是「[ReceivedTime]」。
- 您將電子郵件限制在今天午夜時分收到的電子郵件,而不是午夜後收到的電子郵件。
試試這個代碼:
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 =格式(則DateValue(現在()), 「DDDDD H:NN AMPM」) 集MailItemsToday = FldrInbox.Items.Restrict( 「[ReceivedTime]>'」 &FmtToday&「 '「)。已經改變了我的代碼,它工作。 –