如何统计在 Outlook 中某个约会或会议上所花费的小时数、天数或周数?
假如您在 Outlook 日历中有大量约会和会议,现在希望统计这些约会和会议所花费的小时数、天数或周数,有什么方法可以实现?本文将为您介绍一段 VBA 代码,助您轻松完成统计。
使用 VBA 统计在约会或会议上花费的小时/天/周数
本方法将为您介绍一段 VBA 代码,助您轻松统计 Outlook 中指定约会或会议所耗费的小时数或分钟数。请按照以下步骤操作:
1. 切换到日历文件夹,然后点击选择您希望统计所花费小时数的约会或会议。
2. 请同时按下 Alt+F11 键,即可打开 Microsoft Visual Basic for Applications 窗口。
3. 点击插入 > 模块,然后将以下 VBA 代码粘贴到打开的模块窗口中。
VBA:统计在 Outlook 中约会或会议所花费的小时/分钟数
Sub CountTimeSpent()
Dim oOLApp As Outlook.Application
Dim oSelection As Outlook.Selection
Dim oItem As Object
Dim iDuration As Long
Dim iTotalWork As Long
Dim iMileage As Long
Dim iResult As Integer
Dim bShowiMileage As Boolean
bShowiMileage = False
iDuration = 0
iTotalWork = 0
iMileage = 0
On Error Resume Next
Set oOLApp = CreateObject("Outlook.Application")
Set oSelection = oOLApp.ActiveExplorer.Selection
For Each oItem In oSelection
If oItem.Class = olAppointment Then
iDuration = iDuration + oItem.Duration
iMileage = iMileage + oItem.Mileage
ElseIf oItem.Class = olTask Then
iDuration = iDuration + oItem.ActualWork
iTotalWork = iTotalWork + oItem.TotalWork
iMileage = iMileage + oItem.Mileage
ElseIf oItem.Class = Outlook.olJournal Then
iDuration = iDuration + oItem.Duration
iMileage = iMileage + oItem.Mileage
Else
iResult = MsgBox("Please select some Calendar, Task or Journal items at first!", vbCritical, "Items Time Spent")
Exit Sub
End If
Next
Dim MsgBoxText As String
MsgBoxText = "Total time spent: " & vbNewLine & iDuration & " minutes"
If iDuration > 60 Then
MsgBoxText = MsgBoxText & HoursMsg(iDuration)
End If
If iTotalWork > 0 Then
MsgBoxText = MsgBoxText & vbNewLine & vbNewLine & "Total work recorded; " & vbNewLine & iTotalWork & " minutes"
If iTotalWork > 60 Then
MsgBoxText = MsgBoxText & HoursMsg(iTotalWork)
End If
End If
If bShowiMileage = True Then
MsgBoxText = MsgBoxText & vbNewLine & vbNewLine & "Total iMileage; " & iMileage
End If
iResult = MsgBox(MsgBoxText, vbInformation, "Items Time spent")
ExitSub:
Set oItem = Nothing
Set oSelection = Nothing
Set oOLApp = Nothing
End Sub
Function HoursMsg(TotalMinutes As Long) As String
Dim iHours As Long
Dim iMinutes As Long
iHours = TotalMinutes \ 60
iMinutes = TotalMinutes Mod 60
HoursMsg = " (" & iHours & " Hours and " & iMinutes & " Minutes)"
End Function 4. 请按下 F5 键,或点击运行按钮即可运行此 VBA。
此时将弹出一个对话框,显示所选约会或会议所用的小时数或分钟数,如下图所示:

注意:您可以同时选择多个约会或会议,使用此 VBA 代码统计它们所花费的总小时数或分钟数。
相关文章
最佳办公效率工具
体验全新 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