We have a project at work and basically it should do the following:
- Loop through all Outlook items (main email account and its sub folders)
- Loop through all Outlook items (user created Data Files (PST files) and its sub folders)
- The two loops above should exclude the Yammer Root, Sync Issues, Contacts, and Calendar folders
- Find emails with email bodies that contain a certain text (e.g. XXX-YY-2020777), this is for me the most important code
- Print these in the worksheet:
- main folder - sub folder
- sender
- email subject
- date received
So I found a post useful here, credits to Keith Whatling:
Sub GetEmail()
Dim OutApp As Outlook.Application
Dim Namespace As Outlook.Namespace
Dim Mfolder As Outlook.MAPIFolder
Dim myMail As Outlook.Items
Dim Folder As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim UserFolder As Outlook.MAPIFolder
Set OutApp = New Outlook.Application
Set Namespace = OutApp.GetNamespace("MAPI")
On Error Resume Next
For Each Folder In Namespace.Folders
For Each SubFolder In Folder.Folders
For Each UserFolder In SubFolder.Folders
Debug.Print Folder.Name, "|", SubFolder.Name, "|", UserFolder.Name
Next UserFolder
Next SubFolder
Next Folder
On Error GoTo 0
End Sub
I can combine these two posts:
Excel vba: Looping through all subfolders in Outlook email to find an email with certain subject
But I need some guidance so I can start this.