如何在 Outlook 中將多個資料夾或子資料夾的郵件匯出至 Excel?
若採用手動方式或僅依賴 Outlook 的有限功能,將多個資料夾或子資料夾中的郵件匯出至 Excel 往往相當繁瑣。所幸,還有更高效的方法!本文將為您介紹兩種解決方案:一種是靈活但設定較複雜的 VBA 方法,另一種則是透過 Kutools for Outlook 提供的快速、直覺且使用者友善的操作方式。相較於需手動調整程式碼的 VBA,Kutools for Outlook 僅需點擊幾下,即可輕鬆將郵件匯出至 Excel,大幅節省您的時間與精力。接下來,讓我們深入探討這兩種方法的詳細步驟。
使用 VBA 將多個資料夾/子資料夾的郵件匯出至 Excel(複雜但具彈性)
使用 Kutools for Outlook 將資料夾/子資料夾的郵件匯出至 Excel 👍(高效且使用者友善)
使用 VBA 將多個資料夾/子資料夾的郵件匯出至 Excel
如果您具備程式設計經驗,並需要高度客製化的解決方案,VBA 是一個高效且靈活的選擇。此方法可讓您指定多個資料夾或子資料夾,並將其中的郵件分別匯出至不同的 Excel 檔案。不過,這需要一定的技術能力,並需謹慎編寫與調整程式碼。
步驟 1:開啟 VBA 編輯器
按下 Alt+F11,立即開啟「Microsoft Visual Basic for Applications」視窗!
步驟 2:插入新模組
點選「Insert」>「Module」,然後將下方的 VBA 程式碼貼上至新開啟的模組視窗中。
VBA:將多個資料夾與子資料夾的郵件匯出至 Excel
Const MACRO_NAME = "Export Outlook Folders to Excel"
Sub ExportMain()
ExportToExcel "destination_folder_path\A.xlsx", "your_email_account\folder\subfolder_1"
ExportToExcel "destination_folder_path\B.xlsx", "your_email_account\folder\subfolder_2"
MsgBox "Process complete.", vbInformation + vbOKOnly, MACRO_NAME
End Sub
Sub ExportToExcel(strFilename As String, strFolderPath As String)
Dim olkMsg As Object
Dim olkFld As Object
Dim excApp As Object
Dim excWkb As Object
Dim excWks As Object
Dim intRow As Integer
Dim intVersion As Integer
If strFilename <> "" Then
If strFolderPath <> "" Then
Set olkFld = OpenOutlookFolder(strFolderPath)
If TypeName(olkFld) <> "Nothing" Then
intVersion = GetOutlookVersion()
Set excApp = CreateObject("Excel.Application")
Set excWkb = excApp.Workbooks.Add()
Set excWks = excWkb.ActiveSheet
With excWks
.Cells(1, 1) = "Subject"
.Cells(1, 2) = "Received"
.Cells(1, 3) = "Sender"
End With
intRow = 2
For Each olkMsg In olkFld.Items
If olkMsg.Class = olMail Then
excWks.Cells(intRow, 1) = olkMsg.Subject
excWks.Cells(intRow, 2) = olkMsg.ReceivedTime
excWks.Cells(intRow, 3) = GetSMTPAddress(olkMsg, intVersion)
intRow = intRow + 1
End If
Next
Set olkMsg = Nothing
excWkb.SaveAs strFilename
excWkb.Close
Else
MsgBox "The folder '" & strFolderPath & "' does not exist in Outlook.", vbCritical + vbOKOnly, MACRO_NAME
End If
Else
MsgBox "The folder path was empty.", vbCritical + vbOKOnly, MACRO_NAME
End If
Else
MsgBox "The filename was empty.", vbCritical + vbOKOnly, MACRO_NAME
End If
Set olkMsg = Nothing
Set olkFld = Nothing
Set excWks = Nothing
Set excWkb = Nothing
Set excApp = Nothing
End Sub
Public Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant
Dim varFolder As Variant
Dim bolBeyondRoot As Boolean
On Error Resume Next
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
Do While Left(strFolderPath, 1) = "\"
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
Loop
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
Select Case bolBeyondRoot
Case False
Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
bolBeyondRoot = True
Case True
Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
End Select
If Err.Number <> 0 Then
Set OpenOutlookFolder = Nothing
Exit For
End If
Next
End If
On Error GoTo 0
End Function
Function GetSMTPAddress(Item As Outlook.MailItem, intOutlookVersion As Integer) As String
Dim olkSnd As Outlook.AddressEntry
Dim olkEnt As Object
On Error Resume Next
Select Case intOutlookVersion
Case Is < 14
If Item.SenderEmailType = "EX" Then
GetSMTPAddress = SMTPEX(Item)
Else
GetSMTPAddress = Item.SenderEmailAddress
End If
Case Else
Set olkSnd = Item.Sender
If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
Set olkEnt = olkSnd.GetExchangeUser
GetSMTPAddress = olkEnt.PrimarySmtpAddress
Else
GetSMTPAddress = Item.SenderEmailAddress
End If
End Select
On Error GoTo 0
Set olkSnd = Nothing
Set olkEnt = Nothing
End Function
Function GetOutlookVersion() As Integer
Dim arrVer As Variant
arrVer = Split(Outlook.Version, ".")
GetOutlookVersion = arrVer(0)
End Function
Function SMTPEX(olkMsg As Outlook.MailItem) As String
Dim olkPA As Outlook.propertyAccessor
On Error Resume Next
Set olkPA = olkMsg.propertyAccessor
SMTPEX = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
On Error GoTo 0
Set olkPA = Nothing
End Function 步驟 3:自訂 VBA 程式碼
- 請將上述程式碼中的「destination_folder_path」替換為實際的資料夾路徑,例如「C:\Users\DT 168\Documents\TEST」。
- 請將「your_email_account\folder\subfolder_1」與「your_email_account\folder\subfolder_2」替換為您實際的 Outlook 資料夾路徑,例如「Kelly@extendoffice.com\Inbox\A」與「Kelly@extendoffice.com\Inbox\B」。

步驟 4:執行程式碼
按下「F5」或點選「Run」按鈕以執行程式碼。隨後,在彈出的「Export Outlook Folders to Excel」對話方塊中點選「OK」,即可將所有指定資料夾及其子資料夾中的郵件匯出至 Excel 工作表。
缺點:
- 設定複雜:需謹慎調整程式碼,且須具備 VBA 基礎知識。
- 容易出錯:自訂過程中 slightest 的疏忽都可能導致錯誤或匯出不完整。
- 耗時:不適合用於快速或頻繁的匯出作業。
透過批量處理,徹底革新您的郵件管理方式!
厭倦了重複的郵件作業嗎?Kutools for Outlook 提供「批量處理」工具,助您輕鬆簡化工作流程,節省寶貴時間!
- 🌟 批次回覆多封郵件: 運用範本輕鬆發送大量回覆,省時又省力!
- 📧 個別轉寄: 將多封郵件以一般訊息形式轉寄,而非附加檔案。
- 📝 儲存為多種格式: 一次匯出郵件,即可轉存為 PDF、Word、Excel 等多種格式!

使用 Kutools for Outlook 將資料夾/子資料夾的郵件匯出至 Excel 👍
若想採用更快、更省心的方式,「Kutools for Outlook」提供「將選取的電子郵件儲存為多種格式檔案」功能。此方法因操作簡便、速度飛快且支援多元格式而備受推薦。無論您處理的是少量郵件或大型資料集,Kutools 都能讓您以最少的努力享受流暢體驗。
告別 Outlook 效率低落的困擾!Kutools for Outlook 讓批次處理電子郵件變得更輕鬆——立即體驗 30 天免費試用!立即下載 Kutools for Outlook!!
步驟 1:選取資料夾或子資料夾
前往包含欲匯出郵件的資料夾或子資料夾,按下 Ctrl+A,即可全選清單中的所有郵件!
步驟 2:存取「Save Selected Emails as Files in Various Formats」功能
點選「Kutools」>「批量處理」>「將選取的電子郵件儲存為多種格式的檔案」。

步驟 3:設定匯出選項
- 在「儲存郵件為其他檔案」對話方塊中,選取您要儲存檔案的目標資料夾。
- 選取「Excel 格式」選項。
- 在「保存內容」區段中,選取您要匯出的特定郵件內容(例如標頭、內文)。

步驟 4:完成匯出
點選「OK」即可啟動匯出程序。完成後,所有郵件將以獨立的 Excel 檔案形式儲存於您指定的資料夾中。

優點:
- 快速直覺:只需點擊幾下,就能輕鬆將郵件匯出至 Excel,完全無需技術能力!
- 可自訂輸出內容:自由選擇特定文件類型與內容,精準滿足您的需求!
- 無錯誤流程:避開 VBA 方法的複雜性與潛在錯誤,操作更穩定可靠!
- 專業成果:非常適合打造井然有序的記錄,或高效分享資料!
最佳 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

