一个小错误阻止此计数代码运行。
Sub Count2
Dim objOutlook As Object, objnSpace As Object, objFolder As Object
Dim Count As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objnSpace.Folders("My Personal Emails").Folders("spam")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If
For Each MapiItem In MapiFolderInbox.Messages
Select Case Weekday(MapiItem.TimeReceived)
Case vbMonday
Count = Count + 1
End Select
Next MapiItem
MsgBox "Number of spam messages sent on a Monday: " & Count
End Sub
错误信息:
运行时错误“424”:需要对象
调试器突出显示该行:
For Each MapiItem In MapiFolderInbox.Messages