如果有超过15分钟的未读电子邮件,我正尝试给自己发送一封电子邮件。如果存在旧的未读邮件,则发送电子邮件
的代码,当我手动从Outlook中运行,发送邮件,但我得到一个
运行时错误“-2147221238”(8004010a)
我不能让它从规则运行或与任务时间表独立可能由于上述错误。
Sub checkForUnreadMails()
Dim objFolder, objNamespace
'get running outlook application or open outlook
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
End If
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objMsg = Application.CreateItem(olMailItem)
strFilter = "[received] <= '" & Format(DateAdd("n", -15, Now()), "ddddd h:nn AMPM") & "'"
Debug.Print strFilter
Set inboxItems = objNamespace.GetDefaultFolder(olFolderInbox).Items.Restrict(strFilter)
strFilter = "[Unread] = True"
Set unreadItems = inboxItems.Restrict(strFilter)
For Each itm In unreadItems
With objMsg
.To = "[email protected]"
.Subject = "outlookrule There are unread emails over 15 minutes old in Vision ATM mailbox"
.Categories = "T"
.BodyFormat = olFormatPlain ' send plain text message
.Importance = olImportanceHigh
.Sensitivity = olConfidential
.Send
End With
Next
End Sub
在这行是错误?花一分钟取之旅:http://stackoverflow.com/tour – R3uK
显示第22行错误 - 电子邮件地址 – user3165962