Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 移动邮件运行时错误_Vba_Outlook - Fatal编程技术网

Vba 移动邮件运行时错误

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

我在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 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