如何在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邮件助手并体验吧
最佳 Office 办公效率工具
重磅消息:Kutools for Outlook 推出免费版本!
体验全新 Kutools for Outlook 免费版,70 多个强大功能,永久免费使用!点击立即下载!
🤖 Kutools AI :利用先进的AI技术轻松处理邮件,包括答复、总结、优化、扩展、翻译和撰写邮件。
📧 邮件自动化:自动答复(支持POP和IMAP) /计划发送邮件 /发送邮件时根据规则自动抄送密送 / 自动转发(高级规则) / 自动添加问候语 / 自动将群发邮件拆分为单独邮件 ...
📨 邮件管理:撤回邮件 / 按主题等方式阻止诈骗邮件 / 删除重复邮件 / 高级搜索 / 整合文件夹 ...
📁 附件专家:批量保存 / 批量拆离 / 批量压缩 / 自动保存 / 自动拆离 / 自动压缩 ...
🌟 界面魔法:😊更多精美个性表情 /重要邮件来临时提醒您 / 最小化而非关闭 Outlook ...
👍 一键高效操作:带附件全部答复 /反钓鱼邮件 / 🕘显示发件人时区 ...
👩🏼🤝👩🏻 联系人与日历:从选中的邮件批量添加联系人 / 将联系人组拆分为多个独立组 / 移除生日提醒 ...
使用 Kutools,支持英语、西班牙语、德语、法语、中文及40 多种其他语言,满足您的语言偏好!
一键解锁 Kutools for Outlook。无需等待,立即下载,提升办公效率!

