Skip to main content

如何在Outlook中將超過特定天數的未讀郵件自動標記為已讀?

Author: Xiaoyang Last Modified: 2025-05-12

如果您的收件匣中有許多未讀郵件,通常您可以手動使用「全部標記為已讀」功能將所有未讀郵件標記為已讀。但是,您是否嘗試過在Outlook中不需每次手動設置,就能自動將超過特定天數的未讀郵件標記為已讀呢?

使用VBA代碼自動將超過特定天數的未讀郵件標記為已讀


使用VBA代碼自動將超過特定天數的未讀郵件標記為已讀

要自動將所有超過特定天數的未讀郵件標記為已讀,以下VBA代碼可以幫助您:

1. 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2. 在 Microsoft Visual Basic for Applications 窗口中,雙擊 Project1(VbaProject.OTM) 窗格中的 ThisOutlookSession 以打開模組,然後將以下代碼複製並粘貼到空白模組中。

VBA代碼:自動將超過特定天數的未讀郵件標記為已讀:

Private Sub Application_Startup()
        Call MarkOldUnreadEmailsAsRead
    End Sub
    Private Sub MarkOldUnreadEmailsAsRead()
    Dim xInboxFld As Outlook.Folder
    Dim xAccount As Account
    On Error GoTo L1
    For Each xAccount In Outlook.Application.Session.Accounts
        Set xInboxFld = xAccount.DeliveryStore.GetDefaultFolder(olFolderInbox)
        Call Processfolders(xInboxFld)
    Next xAccount
L1:     Exit Sub
    End Sub
    Private Sub Processfolders(ByVal InboxFld As Outlook.Folder)
    Dim xItems As Outlook.Items
    Dim i As Long
    Dim xSubFld As Outlook.Folder
    On Error Resume Next
    Set xItems = InboxFld.Items
    For i = 1 To xItems.Count
        If DateDiff("d", xItems(i).ReceivedTime, Now) >= 15 Then
           If xItems(i).UnRead = True Then
              xItems(i).UnRead = False
              xItems(i).Save
           End If
        End If
    Next
    If InboxFld.Folders.Count > 0 Then
       For Each xSubFld In InboxFld.Folders
           Call Processfolders(xSubFld)
       Next
    End If
End Sub

注意:在上述代碼中,您可以更改此腳本中的天數:If DateDiff("d", xItems(i).ReceivedTime, Now) >= 15 Then 至您所需的數字。

the screenshot of marking unread emails older than specific days as read automatically in Outlook

3. 然後保存並關閉此代碼窗口,從此以後,每次啟動Outlook時,所有超過預定天數的未讀郵件都會立即自動標記為已讀。

注意:此代碼僅適用於預設數據帳號。