好吧,这就是我所拥有的。似乎没有任何简单的属性或方法可以为您提供所需的答案。我不知道是否有任何方法可以通过 SQL 查询引用邮件项目。如果有,那将是理想的方法。由于这似乎不可能,您唯一的选择是遍历文件夹(或文件夹)中的所有项目,并在一周中的几天有几个计数器变量。然后为每个项目增加适当的计数器。
主要问题只是弄清楚如何引用适当的对象。
在 MS Outlook 2003 中测试,似乎可以正常工作。但是 - 我没有检查它是否计算收件箱每个子文件夹中的每个项目,或者它是否只是计算收件箱本身中的项目,而不是收件箱子文件夹中的任何项目。无论如何,她是:
Sub CountEmailsByDayOfWeek()
'count mail items by day-of-week
'Isaac Comer, 6-3-2011
Dim EmCtSun, EmCtMon, EmCtTue, EmCtWed, EmCtThu, EmCtFri, EmCtSat As Long
Dim myInbox As Variant
Dim BUNCH_OF_Items As Items
Dim myInboxItem As Variant
Set myInbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set BUNCH_OF_Items = myInbox.Items
' < Handle any errors like No such folder here >
' clear counters for each day-of-week
' "EmCt" means "Email Count". It wasn't a good choice of variable name
' because some "Items" aren't "Emails", but I'm not fixing it right now
EmCtSun = 0: EmCtMon = 0: EmCtTue = 0: EmCtWed = 0: EmCtThu = 0: EmCtFri = 0: EmCtSat = 0
' disabled test case with the "first" item in Inbox--testing to make sure I had the object reference correct
' Set myInboxItem = BUNCH_OF_Items(1)
' With myInboxItem
' Debug.Print Chr(34) & .Subject & Chr(34) & " Received: "; .ReceivedTime
' Debug.Print DatePart("w", .ReceivedTime)
' End With
For Each myInboxItem In BUNCH_OF_Items
With myInboxItem
'disabled code that shows the subject line and received time
'Debug.Print Chr(34) & .Subject & Chr(34) & " Received: "; .ReceivedTime
Select Case DatePart("w", .ReceivedTime) ' get the numeric day-of-week corresponding to the vb constants
Case vbSunday
EmCtSun = EmCtSun + 1
Case vbMonday
EmCtMon = EmCtMon + 1
Case vbTuesday
EmCtTue = EmCtTue + 1
Case vbWednesday
EmCtWed = EmCtWed + 1
Case vbThursday
EmCtThu = EmCtThu + 1
Case vbFriday
EmCtFri = EmCtFri + 1
Case vbSaturday
EmCtSat = EmCtSat + 1
End Select
End With
Next
' output
' send output both to a msgbox and the immediate window.
Debug.Print "Counts for Emails received Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday respectively."
Debug.Print EmCtSun; EmCtMon; EmCtTue; EmCtWed; EmCtThu; EmCtFri; EmCtSat
MsgBox _
"Sunday:" & vbTab & vbTab & EmCtSun & vbCrLf & _
"Monday:" & vbTab & vbTab & EmCtMon & vbCrLf & _
"Tuesday:" & vbTab & vbTab & EmCtTue & vbCrLf & _
"Wednesday:" & vbTab & EmCtWed & vbCrLf & _
"Thursday:" & vbTab & EmCtThu & vbCrLf & _
"Friday:" & vbTab & vbTab & EmCtFri & vbCrLf & _
"Saturday:" & vbTab & EmCtSat, _
vbOKOnly + vbInformation, "Count of Items By Day-of-week Received"
End Sub
如果此代码有帮助,请为我投票。我需要积分。:-)