Tuesday, January 10, 2012

Mark all emails as Read in a Specific Folder in Outlook

If you want to mark all mails as read in a specific folder in Outlook.

Here is the code-

Sub mark_emails_read()
'Tools-> REFERENCE-> Microsoft outLook
'declare outlook objects
Dim olapp As Outlook.Application
Dim olappns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oitem As Outlook.MailItem
Dim i As Long

'set outlook objects
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(olFolderInbox)
'set the specific folder name
'Set oinbox = oinbox.Folders("Excel Macros")

If oinbox.Items.Restrict("[UnRead] = True").Count = 0 Then
    MsgBox "NO Unread Email In Inbox"
    Exit Sub
End If

For i = oinbox.Items.Count To 1 Step -1
    If oinbox.Items(i).Class = olMail Then oinbox.Items(i).UnRead = False


End Sub

1 comment:

  1. This code takes forever, is there a way to mark entire folder as unread at once?


Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...