这是我昨天发布的一个问题的后续问题。我觉得我已经非常接近在 VBA 中创建一个模块,该模块将计算一周中特定日期发送的电子邮件数量。目前选择的日期是星期一。
但是,代码还不能工作,Outlook 拒绝查看特定模块。
我确信其中有几个错误。如果有人能指出这些,我将不胜感激。
我还认为此类代码可能对其他人有用以供将来参考,因为此类模块的代码似乎在互联网上并不容易获得(我已经看过了!),但形成了一种搜索参数,许多人会发现有用!
Sub Count2(Optional dteDate As Date)
Dim objOutlook As Object, objnSpace As Object, objFolder As Object
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set objFolder = objnSpace.Folders("My Personal Emails").Folders("spam")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If
Select Case Weekday(dteDate)
Case vbMonday
dteDate = Date
End Select
For Each MapiItem In MapiFolderInbox.Messages
If MapiItem.TimeReceived = Date Then
Count = Count + 1
Next MapiItem
End If
EmailCount = objFolder.Items.Count
Set objFolder = Nothing
Set objnSpace = Nothing
Set objOutlook = Nothing
MsgBox "Number of emails in the folder: " _
& EmailCount, , "Number of spam messages sent on a Monday: " & Count
End Sub