如何在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$("yy@addin99.com") 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 Object Library選項,見截圖:
4. 然後點擊確定關閉對話框,並按F5鍵運行此代碼。隨後,將打開一個Excel文件,顯示特定帳戶每個月發送郵件的計數,見截圖:
Outlook中的AI郵件助理:更聰明的回覆,更清晰的溝通(一鍵奇蹟!) 免費
使用Kutools for Outlook的AI郵件助理簡化您的日常Outlook任務。這個強大的工具會從您過去的郵件中學習,提供智能且準確的答覆,優化您的郵件內容,並幫助您輕鬆起草和潤色郵件。

此功能支援:
- 智能回覆:根據您過去的對話獲得量身定制、精確且隨時可用的回覆。
- 增強內容:自動優化您的郵件文字以提高清晰度和影響力。
- 輕鬆撰寫:只需提供關鍵字,讓AI處理其餘部分,並有多種寫作風格可供選擇。
- 智能擴展:通過上下文感知建議來拓展您的思路。
- 摘要生成:即時獲取長郵件的簡潔概述。
- 全球觸及:輕鬆將您的郵件翻譯成任何語言。
此功能支援:
- 智能郵件回覆
- 優化的內容
- 基於關鍵字的草稿
- 智能內容擴展
- 郵件摘要生成
- 多語言翻譯
最重要的是,此功能永遠完全免費!不要再等待了——立即下載AI郵件助理並享受吧
最佳辦公室生產力工具
最新消息:Kutools for Outlook 推出免費版本!
體驗全新 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