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
Next
End Sub
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
Next
End Sub
This code takes forever, is there a way to mark entire folder as unread at once?
ReplyDelete