跳到主要內容

如何將Outlook郵件計數導出到Excel工作簿?

通常,您可以使用導入/導出功能快速而輕鬆地將Outlook郵件導出到Excel文件。 但是,您是否曾經嘗試對特定電子郵件帳戶的所有文件夾中的項目進行計數並將計數結果導出到Excel工作簿?

使用VBA代碼將Outlook消息計數導出到Excel工作簿


使用VBA代碼將Outlook消息計數導出到Excel工作簿

以下VBA代碼可幫助您將特定電子郵件帳戶中所有文件夾的計數結果導出到Excel工作簿,請執行以下操作:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

VBA代碼:將Outlook項目導出到Excel工作簿中:

Sub Export_CountOfItems_InEachFolder_toExcel()
    Dim xSourceFolder As Outlook.Folder, xSubFolder As Outlook.Folder
   Dim xFilePath As String
    Dim xExcelApp As Excel.Application
    Dim xWb As Excel.Workbook
    Dim xWs As Excel.Worksheet
    On Error Resume Next
    Set xExcelApp = New Excel.Application
    Set xWb = xExcelApp.Workbooks.Add
    Set xWs = xWb.Sheets(1)
    xWs.Cells(1, 1) = "Folder"
    xWs.Cells(1, 2) = "Count Items"
    Set xSourceFolder = Outlook.Application.Session.PickFolder
    If xSourceFolder = nill Then
        xWb.Close False
        xExcelApp.Quit
        Exit Sub
    End If
    For Each xSubFolder In xSourceFolder.Folders
        Call ProcessFolders(xWs, xSubFolder)
    Next
    xWs.Columns("A:B").AutoFit
    Set xShell = CreateObject("Shell.Application")
    Set xFolder = xShell.BrowseforFolder(0, "Select a Folder:", 0, 0)
   If TypeName(xFolder) = "Nothing" Then
        xWb.Close False
        xExcelApp.Quit
        Exit Sub
    End If
    Set xFolderItem = xFolder.Self
    xFilePath = xFolderItem.Path & "\"
    xFilePath = xFilePath & xSourceFolder.Name & "(" & Format(Now, "yyyy-mm-dd hh-mm-ss") & ").xlsx"
    xWb.Close True, xFilePath
    xExcelApp.Quit
    Set xShell = Nothing
    MsgBox "Complete!", vbExclamation, "Kutools for Outlook"
End Sub
Sub ProcessFolders(ByVal Ws As Worksheet, ByVal xCurFolder As Outlook.Folder)
    Dim xSubFld As Folder
    Dim xItemCount As Long
   Dim xRow As Integer
    xItemCount = xCurFolder.Items.Count
    xRow = Ws.UsedRange.Rows.Count + 1
    Ws.Cells(xRow, 1) = xCurFolder.FolderPath
    Ws.Cells(xRow, 2) = xItemCount
    If xCurFolder.Folders.Count > 0 Then
       For Each xSubFld In xCurFolder.Folders
           Call ProcessFolders(Ws, xSubFld)
       Next
    End If
End Sub

3。 而且,仍然在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考參考-Project1 對話框,然後檢查 Microsoft Excel對像庫 選項從 可用參考 列錶框,請參見屏幕截圖:

doc導出項目數1

4。 然後點擊 OK,然後按 F5 運行此代碼的關鍵 選擇“文件夾” 彈出,請選擇您要導出項目計數的電子郵件帳戶,請參見屏幕截圖:

doc導出項目數2

5。 然後點擊 OK,另一個 瀏覽文件夾 顯示,請選擇一個文件夾放置Excel文件,請參見屏幕截圖:

doc導出項目數3

6。 最後點擊 OK 按鈕,並且所選帳戶的所有文件夾中的項目計數已導出到Excel工作簿,您可以打開Excel文件以查看結果,請參見屏幕截圖:

doc導出項目數4


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, CETIN,
Maybe you forgot the step3 in this article, you should check the Microsoft Excel Object Library option in the Available References list box.
please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Sub ProcessFolders(ByVal Ws As Worksheet, ByVal xCurFolder As Outlook.Folder)

This line gives error ;

User -defined type not defined, after pressing F5
This comment was minimized by the moderator on the site
Thank for posting this Code works Exactly as written, Kudos
This comment was minimized by the moderator on the site
This Is Perfect, it worked exactly as it is written, thank you for posting this code
This comment was minimized by the moderator on the site
Doesn't work
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations