移动邮件运行时错误

时间:2013-09-09 12:50:13

标签: 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 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

有错误的行是:

If objItem.ReceivedTime < Now - 50 And objItem.FlagStatus = 1 Then

1 个答案:

答案 0 :(得分:0)

测试每个对象是否为mailitem,因为如果不是,则可能没有ReceivedTimeFlagstatus。尝试类似:

If TypeOf objItem Is MailItem Then
   If objItem.ReceivedTime < Now - 50 And objItem.FlagStatus = 1 Then

...