如何引用项目来统计收件箱中的邮件数量?
一个小错误导致该计数代码无法运行。
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
A small error is preventing this counting code from operating.
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
The error message:
Run-time error '424':
Object required
The debugger highlights the line:
For Each MapiItem In MapiFolderInbox.Messages
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这是一个工作版本:
Ok, here's a working version:
编辑:--根据 VBA 代码中的最后一个字符串判断,您似乎希望对垃圾邮件进行计数。使用 @sitnik 的解决方案似乎是更好的方法。
MapiFolderInbox 似乎未定义 - 尝试将其分配给您的收件箱文件夹,例如:
另请参阅:选项显式打开
Edit: -- it seems you wish to count Spam messages, judging by the last string in your VBA code. Going with @sitnik's solution seems the better approach.
MapiFolderInbox seems to be undefined -- try assigning it to your Inbox folder, something like:
Also see: Option Explicit On