Sub OpenAllUnreadEmails()
Dim objFolders As Outlook.Folders
Dim objFolder As Outlook.Folder
Dim lUnreadMailCount As Long
lUnreadMailCount = 0
'Change "John Smith" to the name of your own Outlook file
Set objFolders = Outlook.Application.Session.Folders("John Smith").Folders
For Each objFolder In objFolders
Call ProcessFolders(objFolder, lUnreadMailCount)
Next
MsgBox "Open " & lUnreadMailCount & " unread emails successfully!", vbExclamation + vbOKOnly, "Batch Open Unread Mails"
End Sub
Sub ProcessFolders(ByVal objCurrentFolder As Outlook.Folder, lCurUnreadEmailCount As Long)
Dim objItem As Object
Dim objMail As Outlook.MailItem
Dim objSubfolder As Outlook.Folder
'Display Unread Emails only
If objCurrentFolder.DefaultItemType = olMailItem Then
For Each objItem In objCurrentFolder.Items
If TypeOf objItem Is MailItem Then
Set objMail = objItem
If objMail.UnRead = True Then
objMail.Display
lCurUnreadEmailCount = lCurUnreadEmailCount + 1
End If
End If
Next
End If
If objCurrentFolder.Folders.Count > 0 Then
For Each objSubfolder In objCurrentFolder.Folders
Call ProcessFolders(objSubfolder, lCurUnreadEmailCount)
Next
End If
End Sub