I have two accounts in Outlook one is my personal and another is shared.
I want to read or unread emails of my shared mail box.
I have code that is working with my personal Inbox.
With my shared email group it is showing
Sub OutlookTesting()
Dim folders As Outlook.folders
Dim Folder As Outlook.MAPIFolder
Dim iRow As Integer
Dim Pst_Folder_Name
Dim MailboxName
Dim UnRow As Integer
Dim RESS As Outlook.Recipient
Dim Flag As Integer
'Mailbox or PST Main Folder Name (As how it is displayed in your Outlook Session)
MailboxName = "Dummi@abc.com" 'Mailbox Folder or PST Folder Name (As how it is displayed in your Outlook Session)
Pst_Folder_Name = "Inbox"
' subfolder name
Dim subFolderName As String
subFolderName = "XYZ"
Set Folder = Outlook.Session.folders(MailboxName).folders(Pst_Folder_Name)
If Folder = "" Then
MsgBox "Invalid Data in Input"
GoTo end_lbl1:
End If
'Read Through each Mail and export the details to Excel for Email Archival
For iRow = 1 To Folder.Items.Count
If (Folder.Items(iRow).UnRead) Then
Flag = 0
Set Res = Folder.Items(iRow).Recipients
For Each RESS In Res
If RESS.Name = "ABCD" Or RESS.Name = "PQRS" Then
Flag = 1
End If
Next
If Flag = 1 Then
Folder.Items(iRow).UnRead = True
Else: Folder.Items(iRow).UnRead = False
End If
End If
Next iRow
MsgBox "Outlook Mails Extracted to Excel"
end_lbl1:
End Sub