Deleted Items - Unable to Iterate All of Items

Not open for further replies.


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("").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
End If
Debug.Print Now()
Debug.Print "Finished"
End Sub

Thanks in advance for ANY thoughts!
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
Kika Melo Outlook Calendar deleted appointments not in Deleted Items folder Using Outlook 3
K Changing the Deleted Items location in Outlook 2019 Using Outlook 2
F Wishlist Outlook suddenly began synchronizing deleted items every time I delete a single email. Using Outlook 2
G Retention Policy for Deleted Items folder Using Outlook 0
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 ? Using 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 Using Outlook 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 Using Outlook 0
N Control ID for Outlook 2013 “Recover Deleted Items From Server” Using Outlook 0
A Creating a rule on “Deleted items” folder Using Outlook 1
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
M Mail being delivered directly to deleted items folder.... Using Outlook 4
R Outlook 2010 Changed "Recover Deleted Items" Behavior Using Outlook 11
S Delete folder without moving to "deleted items" folder Outlook VBA and Custom Forms 1
J Making custom Outlook 2007 folders emptiable like "Deleted Items" Outlook VBA and Custom Forms 1
M Empty Deleted items folder - Other users folder Outlook VBA and Custom Forms 1
E How to access the Deleted Items Folder Outlook VBA and Custom Forms 3
E How to access the Deleted Items Folder Outlook VBA and Custom Forms 3
L Deleted items not displaying in outlook Using Outlook 2
J Emptying multiple Deleted Items folders Outlook VBA and Custom Forms 2

Similar threads