There are some Use Cases where we may have to read the mails from all the Subfolders Present in a Main folder of our Outlook Account.
To achieve this use the below VBA Code to get all the Subfolder with its full Path present in Inbox in your Outlook Account.
Dim olApp As Microsoft.Office.Interop.Outlook.Application
Dim olNs As Microsoft.Office.Interop.Outlook.Namespace
Dim olParentFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderA As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim olFolderB As Microsoft.Office.Interop.Outlook.MAPIFolder
olApp = New Microsoft.Office.Interop.Outlook.Application
olNs = olApp.GetNamespace(“MAPI”)
olParentFolder = olNs.Folders(“YourEmail@outlook.com”).Folders(“Inbox”)
For Each olFolderA In olParentFolder.Folders
OutlookFolderNames.Add(olFolderA.FolderPath)
Next
Note : In the Place of YourEmail@outlook.com put your Email Id from which you wanted to retrieve mail Items.
Click on Edit Arguments and Pass a List(Of String) OutlookFolderNames Variable to hold the value of Subfolder Paths.
Now you have all the Subfolder Paths in a List Variable
- Use for each loop and loop over this List,
In for each use get outlook mail message activity pass the loop item to MailFolder property of get outlook mail message activity
You will get mail items from required subfolder, you can perform your business logic on it or you can add all the mail message to a List of mail messages variable and loop through the mail messages from the list and perform the required operation.
Happy Automation !!
Thanks & Regards,
Rohith