Outlook VBA日期时间过滤器

时间:2017-02-14 09:29:19

标签: vba outlook outlook-vba

我有一个outlook宏,可以读取所有未读电子邮件的所有主题行。

Sub ReadMails()
    Set objOutlook = CreateObject("Outlook.Application")
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objFolderSrc = objFolder.Folders("My Own Folder")

    Dim Subjects() As String
    ReDim Subjects(1 To 1) As String

    Set colItems = objFolderSrc.Items
    Set colFilteredItems = colItems.Restrict("[UnRead] = False")

    For Each objMessage In colFilteredItems
        Subjects(UBound(Subjects)) = objMessage.ConversationTopic
        ReDim Preserve Subjects(1 To UBound(Subjects) + 1) As String
    Next
End Sub

相反,我需要阅读当天和当天早上8点之间发来的电子邮件。

如何添加该过滤器

1 个答案:

答案 0 :(得分:0)

尝试TimeValue Function

实施例

Option Explicit
Public Sub Example()
    Dim EightAM As Date

    EightAM = TimeValue("08:00:00 AM")

    If (TimeValue(Now()) <= EightAM) Then
        ' Do something / Read Email
        Debug.Print TimeValue(Now())
    Else
        ' Do something else
        Debug.Print "bla bla !!!"
    End If
End Sub