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.
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.