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:
Best Office Productivity Tools
Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook
📧 Email Automation: Out of Office (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
📨 Email Management: Easily Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
📁 Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
🌟 Interface Magic: 😊More Pretty and Cool Emojis / Boost Your Outlook Productivity with Tabbed Views / Minimize Outlook Instead of Closing ...
👍 One-click Wonders: Reply All with Incoming Attachments / Anti-Phishing Emails / 🕘Show Sender's Time Zone ...
👩🏼🤝👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Over 100 Features Await Your Exploration! Click Here to Discover More.













