如何將電子郵件從多個文件夾/子文件夾導出到Outlook中的Excel?
使用Outlook中的“導入和導出”嚮導導出文件夾時,它不支持 包括子文件夾 如果將文件夾導出到CSV文件,則為選項。 但是,將每個文件夾導出到CSV文件然後手動將其轉換為Excel工作簿將非常耗時且乏味。 在這裡,本文將介紹一個VBA,可以輕鬆地將多個文件夾和子文件夾快速導出到Excel工作簿。
Kutools for Outlook-為Microsoft Outlook帶來100種強大的高級功能
- 自動CC / BCC 根據規則發送電子郵件; 自動前進 按規則發送多封電子郵件; 自動回复 沒有交換服務器,還有更多自動功能...
- BCC警告 -如果您的郵件地址在密件抄送列表中,則當您嘗試全部答复時顯示消息; 缺少附件時提醒,還有更多提醒功能...
- 回复(全部)帶有所有附件 在郵件對話中; 一次回复許多電子郵件; 自動添加問候語 回复時自動將日期和時間添加到主題中...
- 附件工具:自動分離,全部壓縮,重命名,自動保存所有... 快速報告,計算所選郵件, 刪除重複的郵件和聯繫人...
- 超過 100 項高級功能將 解決您的大部分問題 在 Outlook 2021 - 2010 或 Office 365 中。完整功能 60 天免費試用。
使用VBA將多個文件夾中的多個電子郵件導出到Excel
請按照以下步驟使用Outlook中的VBA將電子郵件從多個文件夾或子文件夾導出到Excel工作簿。
1。 按 其他 + F11 鍵以打開“ Microsoft Visual Basic應用程序”窗口。
2。 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到新的“模塊”窗口中。
VBA:將電子郵件從多個文件夾和子文件夾導出到Excel
Const MACRO_NAME = "Export Outlook Folders to Excel"
Sub ExportMain()
ExportToExcel "destination_folder_path\A.xlsx", "your_email_accouny\folder\subfolder_1"
ExportToExcel "destination_folder_path\B.xlsx", "your_email_accouny\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
'Write Excel Column Headers
With excWks
.Cells(1, 1) = "Subject"
.Cells(1, 2) = "Received"
.Cells(1, 3) = "Sender"
End With
intRow = 2
For Each olkMsg In olkFld.Items
'Only export messages, not receipts or appointment requests, etc.
If olkMsg.Class = olMail Then
'Add a row for each field in the message you want to export
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 olkPrp = Nothing
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)更換 目的地_文件夾_路徑 在上面的代碼以及目標文件夾的文件夾路徑中,您將保存導出的工作簿,例如 C:\ Users \ DT168 \ Documents \ TEST.
(2)將上述代碼中的your_email_accouny \ folder \ subfolder_1和your_email_accouny \ folder \ subfolder_2替換為Outlook中子文件夾的文件夾路徑,例如 凱莉@extendoffice.com \ Inbox \ A 及 凱莉@extendoffice.com \ Inbox \ B
4。 按 F5 鍵或單擊 跑 按鈕以運行此VBA。 然後點擊 OK 彈出Outlook文件夾導出到Excel對話框中的按鈕。 看截圖:
現在,來自以上VBA代碼中所有指定子文件夾或文件夾的電子郵件將被導出並保存到Excel工作簿中。
相關文章
Kutools for Outlook-為Outlook帶來100個高級功能,並使工作更加輕鬆!
- 自動CC / BCC 根據規則發送電子郵件; 自動前進 自定義多封電子郵件; 自動回复 沒有交換服務器,還有更多自動功能...
- BCC警告 -當您嘗試全部答复時顯示消息 如果您的郵件地址在“密件抄送”列表中; 缺少附件時提醒,還有更多提醒功能...
- 在郵件對話中回复(全部)帶有所有附件; 回复許多電子郵件 片刻之間; 自動添加問候語 回复時將日期添加到主題中...
- 附件工具:管理所有郵件中的所有附件, 自動分離, 全部壓縮,重命名全部,保存全部...快速報告, 計算選定的郵件...
- 強大的垃圾郵件 習俗 刪除重複的郵件和聯繫人... 使您能夠在Outlook中做得更聰明,更快和更好。



#23639
網站主持人對此評論進行了最小化
0
0

#25114
網站主持人對此評論進行了最小化
即時報告
0
0

#25115
網站主持人對此評論進行了最小化
即時報告
0
0

#25116
網站主持人對此評論進行了最小化
0
0

#25117
網站主持人對此評論進行了最小化
即時報告
0
0

#25118
網站主持人對此評論進行了最小化
0
0

#33103
網站主持人對此評論進行了最小化
即時報告
0
0

#34351
網站主持人對此評論進行了最小化
即時報告
0
0

#36350
網站主持人對此評論進行了最小化
即時報告
0
0

#36351
網站主持人對此評論進行了最小化
0
0
這裡還沒有評論