Hi,
I use the following code to clean my Outlook inbox. However, I have noticed that sometimes it doesn’t delete all the emails it should delete in the first sweep. It however deletes them in the second or third sweep. Why does it happen?
Question cross posted at:
http://www.vbaexpress.com/forum/showthread.php?t=40759
I use the following code to clean my Outlook inbox. However, I have noticed that sometimes it doesn’t delete all the emails it should delete in the first sweep. It however deletes them in the second or third sweep. Why does it happen?
Code:
Dim oloutlook As Outlook.Application
Dim ns As Outlook.NameSpace
Dim itm As Object
Dim Myitem As MailItem
Dim counter As Integer
Dim olTrash As Object
Set oloutlook = CreateObject("Outlook.Application")
Set ns = oloutlook.GetNamespace("MAPI")
Set itm = ns.GetDefaultFolder(olFolderInbox)
Set olTrash = ns.GetDefaultFolder(olFolderDeletedItems)
For Each MyItem In itm.Items
Select Case UCase(MyItem.SenderName)
Case UCase("ABCD")
MyItem.Move olTrash
counter = counter + 1
Case UCase("EFGH")
MyItem.Move olTrash
counter = counter + 1
End Select
Next
…
Question cross posted at:
http://www.vbaexpress.com/forum/showthread.php?t=40759