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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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