Skip to main content

Kutools for Office — 一套工具,五種功能。完成更多工作。

如何在Outlook中將多個資料夾/子資料夾中的郵件匯出到Excel?

Author Kelly Last modified

如果依賴手動方法或有限的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:插入新模塊

點擊“插入” > “模塊”,然後將以下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代碼

  1. 將上述代碼中的“destination_folder_path”替換為實際的資料夾路徑,例如“C:\Users\DT168\Documents\TEST”。
  2. 替換“your_email_account\folder\subfolder_1” 和 “your_email_account\folder\subfolder_2” 為您的Outlook資料夾路徑,例如 “Kelly@extendoffice.com\收件匣\A” 和 “Kelly@extendoffice.com\收件匣\B".
    doc-export-subfolders-to-excel-1

步驟4:運行代碼

按“F5”鍵或點擊“運行”按鈕執行代碼。然後在彈出的“將Outlook資料夾導出到Excel”對話框中點擊“確定”按鈕。現在,所有指定資料夾/子資料夾中的郵件都被導出到Excel工作簿中。
doc-export-subfolders-to-excel-3

缺點:

  • 複雜設置:需要仔細調整代碼並具備VBA的工作知識。
  • 容易出錯:在自定義過程中出現的小錯誤可能導致錯誤或不完整的導出。
  • 耗時:不適合快速或頻繁的導出。

使用批量處理轉變您的郵件管理!

厭倦了重複的郵件任務? Kutools for Outlook 提供了“批量處理”工具,幫助您簡化工作流程並節省寶貴的時間。

  • 🌟 批量回覆郵件:使用模板輕鬆發送批量回覆。
  • 📧 個別轉寄:將多封郵件作為普通消息轉寄,而不是附件。
  • 📝 另存為多種格式:一次性將郵件導出為PDF、Word、Excel等格式!
Kutools for Outlook Bulk Processing Feature

立即試用Kutools for Outlook


使用Kutools for Outlook將郵件從資料夾/子資料夾匯出到Excel 👍

對於更快且無憂的解決方案,“Kutools for Outlook”提供了“將選定的郵件保存為各種格式的文件”功能。由於其簡潔性、速度和多功能性,此方法非常推薦。無論您是管理少量郵件還是大型數據集,Kutools都能確保流暢的體驗且操作簡單。

告別Outlook效率低下的問題!Kutools for Outlook讓批量郵件處理更輕鬆 — 現在還提供免費的AI功能!立即下載Kutools for Outlook!

步驟1:選擇資料夾或子資料夾

瀏覽到包含要導出郵件的資料夾或子資料夾。按 Ctrl + A 選擇列表中的所有郵件。

步驟2:訪問“將選定的郵件保存為各種格式的文件”功能

點擊“Kutools” > “批量處理” > “將選定的郵件保存為各種格式的文件”。

doc-export-subfolders-to-excel-4

步驟3:配置導出設置

  1. 在“將郵件保存為其他文件”對話框中,選擇要保存文件的目標資料夾。
  2. 選擇“Excel 格式”選項。
  3. 在“保存內容”部分選擇要導出的特定郵件內容(例如,郵件頭、正文)。
    doc-export-subfolders-to-excel-5

步驟4:完成導出

點擊“確定”開始導出過程。完成後,您會在指定的資料夾中找到所有保存為單獨Excel文件的郵件。

doc-export-subfolders-to-excel-6

優勢:

  • 快速直觀:只需點擊幾下即可將郵件導出到Excel——不需要技術技能。
  • 可自定義輸出:選擇特定的文件格式和內容以滿足您的需求。
  • 無錯誤過程:避免與VBA方法相關的複雜性和潛在錯誤。
  • 專業結果:非常適合創建有序記錄或高效共享數據。
注意: 要應用Kutools for Outlook的“將選定的郵件保存為各種格式的文件”工具,首先,您應該下載並安裝Kutools for Outlook

最佳辦公室生產力工具

最新消息:Kutools for Outlook 推出免費版本!

體驗全新 Kutools for Outlook,超過100項精彩功能!立即下載!

🤖 Kutools AI 採用先進的AI技術輕鬆處理郵件,包括答覆、摘要、優化、擴充、翻譯及撰寫郵件。

📧 郵件自動化自動回覆(支援POP及IMAP) / 排程發送郵件 / 發送郵件時根據規則自動抄送密送 / 自動轉發(高級規則) / 自動添加問候語 / 自動分割多收件人郵件為個別郵件 ...

📨 郵件管理撤回郵件 / 根據主題等方式阻止詐騙郵件 / 刪除重複郵件 / 高級搜索 / 整合文件夾 ...

📁 附件專業工具批量保存 / 批量拆離 / 批量壓縮 / 自動保存 / 自動拆離 / 自動壓縮 ...

🌟 介面魔法😊更多精美與酷炫表情符號 /重要郵件來臨時提醒 / 最小化 Outlook 而非關閉 ...

👍 一鍵便利帶附件全部答復 / 防詐騙郵件 / 🕘顯示發件人時區 ...

👩🏼‍🤝‍👩🏻 聯絡人與日曆從選中郵件批量添加聯絡人 / 分割聯絡人組為個別組 / 移除生日提醒 ...

以您偏好的語言使用 Kutools,支援英語、西班牙語、德語、法語、中文及超過40種其他語言!

只需點擊一次,即可立即解鎖 Kutools for Outlook。別等了,現在下載提升您的工作效率!

kutools for outlook features1 kutools for outlook features2

🚀 一鍵下載 — 獲取全部 Office 插件

強力推薦:Kutools for Office(5合1)

一鍵下載五個安裝程式,包括 Kutools for Excel, Outlook, Word, PowerPointOffice Tab Pro 立即下載!

  • 一鍵便利:一次操作即可下載全部五套安裝包。
  • 🚀 隨時處理任何 Office 任務:安裝您需求的插件,隨時隨地。
  • 🧰 包含:Kutools for Excel / Kutools for Outlook / Kutools for Word / Office Tab Pro / Kutools for PowerPoint