如何在 Outlook 中統計每月發送的電子郵件數量?
有時,您可能想知道每月發送了多少封電子郵件。 本教程將介紹一個 VBA 代碼,用於統計 Outlook 中每月發送的電子郵件數量。
使用 VBA 代碼計算 Outlook 中每月發送的電子郵件數量
請應用以下 VBA 代碼來獲取每月發送的電子郵件數量,如下所示:
1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。
2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。
VBA 代碼:統計每月發送的電子郵件數量:
Dim GDictionary As Object
Sub CountSentMailsByMonth()
'Updateby Extendoffice
Dim xSentFolder As Outlook.Folder
Dim xExcelApp As Excel.Application
Dim xWb As Excel.Workbook
Dim xWs As Excel.Worksheet
Dim xMonths As Variant
Dim xItemsCount As Variant
Dim xLastRow As Integer
Dim I As Integer
Dim xAccount As Account
On Error Resume Next
Set GDictionary = CreateObject("Scripting.Dictionary")
For Each xAccount In Application.Session.Accounts
If VBA.LCase$(xAccount.SmtpAddress) = VBA.LCase$("") Then 'Specify the Email Account
Set xSentFolder = xAccount.DeliveryStore.GetDefaultFolder(olFolderSentMail)
If xSentFolder.DefaultItemType = olMailItem Then
Call ProcessFolders(xSentFolder)
End If
End If
Next
Set xSentFolder = Nothing
Set xExcelApp = CreateObject("Excel.Application")
xExcelApp.Visible = True
Set xWb = xExcelApp.Workbooks.Add
Set xWs = xWb.Sheets(1)
With xWs
.Cells(1, 1) = "Month"
.Cells(1, 2) = "Count"
.Cells(1, 1).Font.Bold = True
.Cells(1, 2).Font.Bold = True
.Cells(1, 1).HorizontalAlignment = xlCenter
.Cells(1, 2).VerticalAlignment = xlCenter
End With
xMonths = GDictionary.Keys
xItemsCount = GDictionary.Items
For I = LBound(xMonths) To UBound(xMonths)
xLastRow = xWs.Range("A" & xWs.Rows.Count).End(xlUp).Row + 1
With xWs
.Cells(xLastRow, 1) = xMonths(I)
.Cells(xLastRow, 2) = xItemsCount(I)
End With
Next
xWs.Columns("A:B").AutoFit
xExcelApp.Visible = True
Set xExcelApp = Nothing
Set xWb = Nothing
Set xWs = Nothing
End Sub
Sub ProcessFolders(ByVal Fld As Outlook.Folder)
Dim I As Long
Dim xMail As Outlook.MailItem
Dim xMonth As String
Dim xSubFolder As Folder
On Error Resume Next
For I = Fld.Items.Count To 1 Step -1
If Fld.Items(I).Class = olMail Then
Set xMail = Fld.Items(I)
xMonth = Year(xMail.SentOn) & "/" & Month(xMail.SentOn)
If GDictionary.Exists(xMonth) Then
GDictionary(xMonth) = GDictionary(xMonth) + 1
Else
GDictionary.Add xMonth, 1
End If
End If
Next
If Fld.Folders.Count > 0 Then
For Each xSubFolder In Fld.Folders
Call ProcessFolders(xSubFolder)
Next
End If
End Sub
3。 仍在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考在 參考項目 對話框,檢查 Microsoft Excel 16.0 對像庫 選項從 可用參考 列錶框,請參見屏幕截圖:
4。 然後點擊 OK 關閉對話框,然後按 F5 運行此代碼的關鍵。 然後,將打開一個 Excel 文件,其中顯示特定帳戶每個月發送的電子郵件計數,見截圖:
最佳辦公生產力工具
Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook
🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……
📧 電子郵件自動化: 外出(適用於 POP 和 IMAP) / 安排發送電子郵件 / 發送電子郵件時按規則自動抄送/密件副本 / 自動轉送(進階規則) / 自動添加問候語 / 自動將多收件者電子郵件拆分為單獨的訊息 ...
📨 電子郵件管理: 輕鬆回憶電子郵件 / 按主題和其他人阻止詐騙電子郵件 / 刪除重複的電子郵件 / 進階搜索 / 合併資料夾 ...
📁 附件專業版: 批量保存 / 批量分離 / 批量壓縮 / 自動保存 / 自動分離 / 自動壓縮 ...
🌟 介面魔法: 😊更多又漂亮又酷的表情符號 / 使用選項卡式視圖提高 Outlook 工作效率 / 最小化 Outlook 而不是關閉 ...
👍 一鍵奇蹟: 使用傳入附件回覆全部 / 反網路釣魚電子郵件 / 🕘顯示寄件者的時區 ...
👩🏼🤝👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人 / 將聯絡人群組拆分為各組 / 刪除生日提醒 ...
超過 100特點 等待您的探索! 按此處了解更多。