Reputation: 639
Recently had an employee leave the company and decided to move a few thousand emails and events to the trash folder in Outlook. Thankfully, I can still recover them manually but I would prefer not have to do them in small batches..
I've got this code but it errors when I try to move items from the "Deleted Items" folder back to the Inbox.
Sub MoveItems()
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(Deleted Items)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("olFolderInbox")
Set myItem = myItems.Find("[SenderName] = 'John Smith'")
While TypeName(myItem) <> "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
End Sub
Thoughts?
Upvotes: 0
Views: 927
Reputation: 3261
You have to specify the deleted items folder like so:
Set myInbox = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
You can read more examples for specifying folders here and a list of other options here
Upvotes: 1