Vba 移动邮件运行时错误
我在Outlook中设置了一个宏,该宏正在工作,但在过去几天中,它已停止将收到的电子邮件归档到特定文件夹,并出现运行时错误438对象不支持此属性或方法错误 首先是守则:Vba 移动邮件运行时错误,vba,outlook,Vba,Outlook,我在Outlook中设置了一个宏,该宏正在工作,但在过去几天中,它已停止将收到的电子邮件归档到特定文件夹,并出现运行时错误438对象不支持此属性或方法错误 首先是守则: Dim ns As Outlook.NameSpace Dim objItem As Object Dim FolderInbox As Folder Dim MyItem As Outlook.MailItem '// Added - A collection to hold the IDs of message to be
Dim ns As Outlook.NameSpace
Dim objItem As Object
Dim FolderInbox As Folder
Dim MyItem As Outlook.MailItem
'// Added - A collection to hold the IDs of message to be deleted
Dim cMAILS As Collection
Set ns = Application.GetNamespace("MAPI")
Set FolderInbox = ns.GetDefaultFolder(olFolderInbox)
Set cMAILS = New Collection
For Each objItem In FolderInbox.Items
' here is the error
If objItem.ReceivedTime < Now - 50 And objItem.FlagStatus = 1 Then
' Here is a series of code in place
' to move copies of messages to different folder
Next
On Error Resume Next
Do While cMAILS.Count > 0
Set MyItem = ns.GetItemFromID(cMAILS(1))
If Not MyItem Is Nothing Then
MyItem.Delete
End If
cMAILS.Remove (1)
Loop
将ns设置为Outlook.NameSpace
作为对象的Dim objItem
Dim FolderInbox作为文件夹
将MyItem设置为Outlook.MailItem
“//添加了一个集合,用于保存要删除的邮件的ID
Dim cMAILS作为集合
Set ns=Application.GetNamespace(“MAPI”)
设置FolderInbox=ns.GetDefaultFolder(olFolderInbox)
设置cMAILS=新集合
对于FolderInbox.Items中的每个对象项
“这是错误
如果objItem.ReceivedTime0时执行此操作
设置MyItem=ns.GetItemFromID(cMAILS(1))
如果不是MyItem则为Nothing
我的项目。删除
如果结束
cMAILS.Remove(1)
环
出现错误的行是:
If objItem.ReceivedTime < Now - 50 And objItem.FlagStatus = 1 Then
如果objItem.ReceivedTime
测试每个对象是否为邮件项,因为如果不是,它们可能没有接收时间
或标记状态
。尝试以下方法:
If TypeOf objItem Is MailItem Then
If objItem.ReceivedTime < Now - 50 And objItem.FlagStatus = 1 Then
如果objItem的类型是MailItem,则
如果objItem.ReceivedTime