'MailItem.Move method for mail that is read

I'm trying to first check if mails in a specific folder ("pending") are read. If the mail is read, move it to another specific folder ("done").

For the remaining mails in "pending", save the attachments and mark them as "read".

When I try to move each read mail from the "pending" folder to "done" with ".Move", drops

"error 424. An object is required".

The problem is OItem.Move OFolderDst.

Sub MoveInbox2Reviewed()

Dim OutlookApp As Outlook.Application
Dim ONameSpace As Object
Dim OItem As Outlook.MailItem
Dim OFolderSrc As Object
Dim OFolderDst As Object
Dim Path As String

Set OutlookApp = New Outlook.Application
Set ONameSpace = OutlookApp.GetNamespace("MAPI")

Set OFolderSrc = ONameSpace.GetDefaultFolder(olFolderInbox).Folders("pending")
Set OFolderDst = ONameSpace.GetDefaultFolder(olFolderInbox).Folders("done")

Path = "C:\Users\..."

For Each OItem In OFolderSrc.Items.Restrict("[Unread] = False")
    OItem.Move OFolderDst 'The problem is here
Next

For Each OItem In OFolderSrc.Items
    OItem.Attachments.SaveAsFile Path & Attachment.DisplayName
    OItem.UnRead = False
Next

End Sub


Solution 1:[1]

Each time the Move call is made the collection is decreased by one item. So, I'd recommend using the reverse for loop instead for moving items from a folder. For example:

for i = Items.Count to 1 step -1
  Items(i).Move folder
next

So, in the code you may get all unread items (represented by the Items collection) and then call a reverse loop to move items.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev