VBA for MS Outlook Folder Tree

judgepax

Board Regular
Joined
Jan 20, 2009
Messages
53
I have a fairly complex Outlook folder tree with many folders, subfolders, sub-subfolders, etc. and three diferrent archives. I would like to run a script that extracts the entire tree into an Excel or .csv file. Brownie points if it could also extract a count of how many mail messages were in each folder and the datestamp of the most recent message.

I have been unable to find anything useful online but there has to be someway to do this, so here's hoping someone can help...

FYI: I am using MS Outlook 2003 SP3 not Express nor a web-based Outlook interface.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello, does the below help at all ?

This is an adaptation (and a very slight one) of the code found here

Code:
Public rngPath As Range
Public RowNo As Long
Public lCountOfFound As Long

Public Sub WalkFolders()
Dim olApp As Outlook.Application
Dim olSession As Outlook.Namespace
Dim olSessionFolder As Outlook.MAPIFolder
Set olApp = New Outlook.Application
Set olSession = olApp.GetNamespace("MAPI")
RowNo = 1
lCountOfFound = 0
For Each olSessionFolder In olSession.Folders
    ProcessFolder olSessionFolder
Next olSessionFolder
Columns("A:B").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo
End Sub

Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)
Set rngPath = Cells(RowNo, 1)
Dim i As Long
Dim olNewFolder As Outlook.MAPIFolder
Dim olTempFolder As Outlook.MAPIFolder
Dim olTempFolderPath As String
For i = CurrentFolder.Folders.Count To 1 Step -1
    Set olTempFolder = CurrentFolder.Folders(i)
    olTempFolderPath = olTempFolder.FolderPath
    Cells(RowNo, 1) = olTempFolderPath
    Cells(RowNo, 2) = IIf(olTempFolder.Folders.Count, vbNullString, olTempFolder.Items.Count)
    RowNo = RowNo + 1
    lCountOfFound = lCountOfFound + 1
Next
For Each olNewFolder In CurrentFolder.Folders
    ProcessFolder olNewFolder
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,762
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top