dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
The code below is listing the Outlook path for all my Outlook Folders but only two levels deep.
e.g., \\Douglas.Markham@thecompany.com\Inbox\01) doug's jobs\completed jobs
I've tried to nest a third For loop into the code to pull out the next level of folder e.g.,
\\Douglas.Markham@thecompany.com\Inbox\01) doug's jobs\completed jobs\1) Set-up meeting in meeting room 1
When I run the code, I get the following error:
I have two issues I'm trying to solve:
1) I have up to 5 levels of nesting in my Outlook folders: would anyone please be willing to help me modify the code so I can pull out all the sub-folders?
2) This above code prints the folder paths into the Immediate window in VB Editor. Would anyone be willing to help me export the results to a specific excel file instead?
Kind regards,
Doug.
The code below is listing the Outlook path for all my Outlook Folders but only two levels deep.
e.g., \\Douglas.Markham@thecompany.com\Inbox\01) doug's jobs\completed jobs
I've tried to nest a third For loop into the code to pull out the next level of folder e.g.,
\\Douglas.Markham@thecompany.com\Inbox\01) doug's jobs\completed jobs\1) Set-up meeting in meeting room 1
When I run the code, I get the following error:
VBA Code:
Sub Level3()
'Needs reference to MS Outlook Object Library
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olParentFolder As Outlook.MAPIFolder
Dim olFolderA As Outlook.MAPIFolder
Dim olFolderB As Outlook.MAPIFolder
Dim olFolderC As Outlook.MAPIFolder
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olParentFolder = olNs.Folders("Douglas.Markham@thecompany.com").Folders("Inbox")
For Each olFolderA In olParentFolder.Folders
Debug.Print olFolderA.FolderPath ', olFolderA.Items.Count ', olFolderA.Folders.Count
For Each olFolderB In olFolderA.Folders
Debug.Print olFolderB.FolderPath ', olFolderB.Items.Count
Next
'My addition to the code (first line below) that causes run-time error 91
For Each olFolderC In olFolderB.Folders
Debug.Print olFolderC.FolderPath, olFolderC.Items.Count
Next
Next
End Sub
I have two issues I'm trying to solve:
1) I have up to 5 levels of nesting in my Outlook folders: would anyone please be willing to help me modify the code so I can pull out all the sub-folders?
2) This above code prints the folder paths into the Immediate window in VB Editor. Would anyone be willing to help me export the results to a specific excel file instead?
Kind regards,
Doug.