Mark unread email as read by vba

kamel83

New Member
Joined
Dec 5, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Mobile
I need help of getting the formula to make a applucation that makes unread mail in outlook as read
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
First, set the following reference...

VBA Code:
Visual Basic Editor (Alt+F11) >> Tools >> References >> check/select Microsoft Outlook XX.0 Object Library >> click OK

Then copy/paste the following code into a regular module (Visual Basic Editor >> Insert >> Module)...

VBA Code:
Option Explicit

Sub MarkEmailsRead()

    Dim olApp As Outlook.Application
    Set olApp = New Outlook.Application
   
    Dim olNS As Outlook.Namespace
    Set olNS = olApp.GetNamespace("MAPI")
   
    Dim olInbox As Outlook.Folder
    Set olInbox = olNS.GetDefaultFolder(olFolderInbox)
   
    Dim olItems As Outlook.Items
    Set olItems = olInbox.Items.Restrict("[UNREAD]=TRUE")
   
    Dim olItem As Variant
    For Each olItem In olItems
        If TypeName(olItem) = "MailItem" Then
            olItem.UnRead = False
        End If
    Next olItem
   
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top