Tuesday, January 10, 2012

Mark all emails as Read in Outlook Inbox Folder

If you want to mark all mails as read in your outlook Inbox.

Here is the code -

Sub mark_all_unread_mails_as_read_in_inbox_excluding_subfolders()
'TOOLS ->Refrence -> 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
'set outlook objects
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(olFolderInbox)
If oinbox.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "NO Unread Email In Inbox"
Exit Sub
End If
Do Until oinbox.Items.Restrict("[UnRead] = True").Count = 0
For Each oitem In oinbox.Items.Restrict("[UnRead] = True")
oitem.UnRead = False
End Sub

No comments:

Post a Comment