如何將 Outlook 中的資料夾結構匯出至 Excel?
本文將引導您逐步將 Outlook 帳戶的資料夾結構匯出至 Excel 檔案,請依照以下詳細步驟操作。
使用 VBA 程式碼將帳戶的資料夾結構從 Outlook 匯出至 Excel
使用 VBA 程式碼將帳戶的資料夾結構從 Outlook 匯出至 Excel
下列 VBA 程式碼可助您一臂之力,請依照以下步驟操作:
1. 啟動 Excel,並按住 ALT + F11 鍵,即可開啟 Microsoft Visual Basic for Applications 視窗。
2. 點選插入> 模組,並將下列程式碼貼到模組視窗中。
VBA 程式碼:將帳戶的資料夾結構從 Outlook 匯出至 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. 在 Microsoft Visual Basic for Applications 視窗中,點選工具> 參考項目,開啟 參考項目 - Project 1 對話方塊,並於可用參考項目清單中勾選 Microsoft Excel 物件程式庫選項,如下圖所示:

4. 接著點選確定按鈕,再按下 F5 鍵執行此程式碼,系統將彈出選擇資料夾對話方塊,請選取您要匯出資料夾結構的電子郵件帳戶,如下圖所示:

5. 接下來點選確定按鈕,隨即會彈出另存檔案視窗,請立即指定匯出檔案的儲存位置與檔名,如下圖所示:

6. 最後點選儲存按鈕,即可在您指定的 Excel 工作表中查看已匯出的資料夾結構,如下圖所示:

最佳 Office 生產力工具
體驗全新 Kutools for Outlook,內含 100+ 項超強功能!立即點擊下載!
🤖KUTOOLS AI:運用先進 AI 技術,輕鬆處理電子郵件——無論是回覆、摘要、優化、擴充、翻譯還是撰寫郵件,通通一鍵搞定!
📧 郵件自動化:自動答覆(支援 POP 與 IMAP)/預約寄送郵件/寄信時依規則自動抄送密送/自動轉發(高級規則)/自動加入問候語/自動將多收件人郵件拆分為個別訊息……
📨 郵件管理:撤回郵件/依主旨等條件封鎖詐騙郵件/刪除重複郵件/高級搜尋/整合文件夾……
📁 附件專業版:批次儲存/批次解除附加/批次壓縮/自動保存/自動拆離/自動壓縮……
🌟 介面魔法:😊更多精美酷炫表情符號/重要郵件來到時提醒您/最小化 Outlook 而非關閉……
👍 一鍵奇蹟:帶附件全部答復/防釣魚郵件/🕘顯示發送者當前時間時區……
👩🏼🤝👩🏻 聯絡人與行事曆:從選取的郵件中批次新增聯絡人/將聯繫人組拆分為個別群組/移除生日提醒……
用您的慣用語言暢享 Kutools — 完整支援英文、西班牙文、德文、法文、中文等 40 多種語言!
立即一鍵解鎖 Kutools for Outlook!別再等待,馬上下載,全面提升工作效率!


🚀 一鍵下載 — 立即取得所有 Office 增益集
強烈推薦:Kutools for Office(5 合 1)
一鍵下載五個安裝程式,一次完成 — Kutools for Excel、Outlook、Word、PowerPoint 與 Office Tab Pro!立即點擊下載!
- ✅ 一鍵便利:只需一次操作,即可下載全部五個安裝套件!
- 🚀 隨時應對任何 Office 任務:按需安裝所需增益集,立即提升工作效率!
- 🧰 包含:Kutools for Excel/Kutools for Outlook/Kutools for Word/Office Tab Pro/Kutools for PowerPoint