How to export folder structure from Outlook to Excel?
This article, I will introduce how to export folder structure of an account from Outlook to Excel file. Please achieve it with the details of this article.
Export folder structure of an account from Outlook to Excel by using VBA code
Export folder structure of an account from Outlook to Excel by using VBA code
The following VBA code may do you a favor, please do with below steps:
1. Enable Excel and hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Export folder structure of an account from Outlook to Excel:
Dim xExcelApp As Excel.Application
Dim xWb As Excel.Workbook
Dim xWs As Excel.Worksheet
Dim xMainFolderCount As Long
Sub OutlookExportFolderStructureToExcel()
Dim xFolder As Folder
Dim xExcelFile As String
Dim xFileDialog As FileDialog
On Error Resume Next
Set xFolder = Outlook.Application.Session.PickFolder
If xFolder Is Nothing Then Exit Sub
Set xExcelApp = New Excel.Application
Set xWb = xExcelApp.Workbooks.Add
Set xWs = xWb.Sheets(1)
With xWs.Range("A1", "A1")
.Value = "Folder Structure"
.Font.Size = 14
.Font.Bold = True
End With
xMainFolderCount = Len(xFolder.FolderPath) - Len(Replace(xFolder.FolderPath, "\", "")) + 1
Call ExportToExcel(xFolder.FolderPath, xFolder.Name)
Call ProcessFolders(xFolder.Folders)
xWs.Columns("A").AutoFit
Set xFileDialog = xExcelApp.FileDialog(msoFileDialogSaveAs)
With xFileDialog
.AllowMultiSelect = False
.FilterIndex = 1
If .Show = 0 Then
xWb.Close False
xExcelApp.Quit
Set xExcelApp = Nothing
Exit Sub
End If
xExcelFile = .SelectedItems.Item(1)
End With
xWb.Close True, xExcelFile
MsgBox "Export complete!", vbExclamation, "Kutools for Outlook"
End Sub
Sub ProcessFolders(ByVal xFlds As Folders)
Dim xSubFolder As Folder
For Each xSubFolder In xFlds
If xSubFolder.Name <> "Conversation Action Settings" And xSubFolder.Name <> "Quick Step Settings" Then
Call ExportToExcel(xSubFolder.FolderPath, xSubFolder.Name)
Call ProcessFolders(xSubFolder.Folders)
End If
Next
End Sub
Sub ExportToExcel(ByRef xFolderPath As String, xFolderName As String)
Dim i, n As Long
Dim xPrefix As String
Dim xLastRow As Integer
i = Len(xFolderPath) - Len(Replace(xFolderPath, "\", "")) - xMainFolderCount
For n = 0 To i
xPrefix = xPrefix & "-"
Next
xFolderName = xPrefix & xFolderName
xLastRow = xWs.UsedRange.Rows.Count + 1
xWs.Range("A" & xLastRow) = xFolderName
End Sub
3. Still in the Microsoft Visual Basic for Applications window, click Tools > References to go to the References-Project1 dialog box, and check Microsoft Excel Object Library option from the Available References list box, see screenshot:
4. Then click OK button, and press F5 key to run this code, a Select Folder dialog box is popped out, please select the email account that you want to export its folder structure, see screenshot:
5. And then, click OK button, a File Save window is displayed, please specify a location and file name for this exported file, see screenshot:
6. At last, click Save button, and you can go to the specific excel workbook you have saved to view the exported folder structure, see screenshot:
Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!
- Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
- BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
- Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
- Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
- Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.














