Deleted Items - Unable to Iterate All of Items

Status
Not open for further replies.

parisi

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
I have the following code which moves each of the MailItems from deleted items to another folder. I have 34,054 items in Deleted Items. When I run the code it only sees 117. I am pretty sure the code is not seeing all the messages residing on Office 365.

When I click on the Deleted Items folder it indicates that I have 34,054 items. When I scroll to the bottom of the list (a couple hundred at best) I have a "Click here to view more on Microsoft Exchange". If I click that and wait, the list populates with lots of items. When I run my code again, it still only sees 117.

Is there a way to tell this to run against the server or to tell Outlook to actually download all these messages.

Sub RemoveAllItemsAndFoldersInDeletedItems()
Dim oDeletedItems As Outlook.Folder
Dim oFolders As Outlook.Folders
Dim oItems As Outlook.Items
Dim oFolder As Outlook.Folder
Dim omItem As Outlook.MailItem

Dim i As Long
'Obtain a reference to deleted items folder
Set oDeletedItems = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oFolder = Application.Session.Folders.Item("xxx@xxx.com").Folders.Item("Sort")

Set oItems = oDeletedItems.Items
Debug.Print "Start"
Debug.Print Now()
Debug.Print oItems.Count
For i = oItems.Count To 1 Step -1
If TypeOf oItems.Item(i) Is Outlook.MailItem Then
Set omItem = oItems.Item(i)
omItem.Move oFolder
DoEvents
End If
DoEvents
Next
Debug.Print Now()
Debug.Print "Finished"
End Sub


Thanks in advance for ANY thoughts!
Paul.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
V Unable to delete from deleted items folder due to error message Using Outlook 3
F Unable to recover deleted items Using Outlook 2
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
D Unopened message in inbox deleted and not in deleted items Using Outlook 3
R Exporting recovered Deleted Items outside the Inbox Using Outlook 1
R Retention periods and Deleted Items Using Outlook 7
icacream Can't the Deleted Items Folder be self cleaning ? Using Outlook 2
M How many days are items in Recover Deleted at Outlook.com ? Using Outlook.com accounts in Outlook 4
C Outlook is permanently deleting deleted items (purging) Using Outlook 0
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
Jeanne Goodman Delete Calendar Item Bypassing Deleted Items folder Outlook VBA and Custom Forms 2
Diane Poremsky Moving Deleted Items New Slipstick.com Articles 0
P Deleting items in folders doesnt send them to deleted items! Using Outlook 4
Rupert Dragwater Some mailboxes show deleted items as not read Using Outlook 5
norbertlars Outlook - deleted items Using Outlook 5
Rupert Dragwater Deleting email from Deleted Items does not work Using Outlook 0
Jessica .msg file saved in network drive appearing in Deleted Items folder Using Outlook 3
K Deleted calendar and contact items not going to delete folder Using Outlook 1
K Outlook 2013 Deleted calendar and contact items not going to delete folder Exchange Server Administration 1
Diane Poremsky Shared Mailboxes and the Deleted Items Folder New Slipstick.com Articles 0
N Control ID for Outlook 2013 “Recover Deleted Items From Server” Using Outlook 0
N Messages still in 'Deleted items' folder even after deleting! Using Outlook 2
S Can't move the items. The item could not be moved. It was either already moved or deleted, or access Using Outlook 3
M recover deleted items vba macro Outlook VBA and Custom Forms 2
T Outlook 2013: How did "Inbox" emails jump straight to the "Recover Deleted Items" Folder? Using Outlook 2
I Event listener for deleted items Using Outlook 6
A Prompt on exit to empty deleted items folder "for all accounts" does not work? Using Outlook 6
N Recovering deleted items Exchange Server Administration 0
D Outlook 2013 deletes emails, does not send them to Deleted Items or Trash Using Outlook 2
E The RECOVER DELETED ITEMS is grayed out and i can't recover my messages Using Outlook 1
D Deleted Items Using Outlook 5
L Recover Deleted Items Folder shows email which are not really deleted. Using Outlook 0
I How do I completely delete contents of "deleted items" to reduce pst file size Using Outlook 1
C Tracking WHO deleted items in a Shared Mailbox Using Outlook 1
C Outlook 2007 - Recover Deleted Items - Columns to Choose from Using Outlook 1
C Outlook/Exchange 2010 Recover Deleted Items to original folder Using Outlook 2
P deleted items keep reappearing in my deleted folder Using Outlook 4
G Deleted Items and Inbox archives in different folders?? Using Outlook 2
D Exchange 2010 SP1 Policy to Delete mail in deleted items older than 30 days Exchange Server Administration 2
R Synced Items get Deleted Using Outlook 5
I Prompt before sending contacts to Deleted Items folder Using Outlook 7
S Outlook 2010 Not Closing if option 'Emty deleted items folders when exiting outlook' is enabled Using Outlook 2
M How do I recover all items in a deleted Outlook 2007 calendar not using Exchange Server? Using Outlook 3
O Item won't delete out of Deleted Items in Outlook.... Using Outlook 2
K Retention Tags - expired items not deleted from Deleted Items Exchange Server Administration 21
H Deleted items from IMAP account in Outlook 2007 disappear! How do I route them back to "Deleted Item Using Outlook 5
M Mail being delivered directly to deleted items folder.... Using Outlook 4
R Outlook 2010 Changed "Recover Deleted Items" Behavior Using Outlook 11
B Error message with Outlook 2010: Deleted items folder is unavailable Using Outlook 19
S Delete folder without moving to "deleted items" folder Outlook VBA and Custom Forms 1

Similar threads

Top