2017-07-04 28 views
0

我試圖閱讀僅在今天收到的郵件。下面是我限制的代碼,但是它拋出了一個無效的錯誤條件。當我給出如unread = True的條件時,工作正常。通過郵件列表中的ReceivedTime設置限制

Set myItems = myItems.Restrict("DateValue[ReceivedTime]='" & Format(DateValue(Now),"ddddd h:nn AMPM") & "'") 

請幫我解決這個問題。

回答

0

我看到至少有兩個問題。

  1. 您有「DateValue [ReceivedTime]」而不是「[ReceivedTime]」。
  2. 您將電子郵件限制在今天午夜時分收到的電子郵件,而不是午夜後收到的電子郵件。

試試這個代碼:

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 
+0

感謝您的答覆託尼。它確實幫助 '點心FmtToday作爲字符串 FmtToday =格式(則DateValue(現在()), 「DDDDD H:NN AMPM」) 集MailItemsToday = FldrInbox.Items.Restrict( 「[ReceivedTime]>'」 &FmtToday&「 '「)。已經改變了我的代碼,它工作。 –