• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

deleting spam in both accounts

Belleke

Well-Known Member
Hi,
I have this code to empty junkfolders in outlook.
Unfortunately, it only works for the default account, what can I do to let it work for both accounts?
Thanks.
Code:
Sub EmptyDeletedItems()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim objExpl As Outlook.Explorer
Dim mboxCount As Long
Dim i As Long
Dim deletedItemsFolder As Outlook.Folder
 
Set olApp = Application
Set olNS = olApp.GetNamespace("MAPI")
Set objExpl = olApp.ActiveExplorer
 
mboxCount = olNS.Folders.Count
For i = 1 To mboxCount
  On Error Resume Next
  Set deletedItemsFolder = olNS.Folders(i).Folders("Deleted Items")
  If Err = 0 Then
    On Error GoTo 0
    objExpl.SelectFolder deletedItemsFolder
     objExpl.CommandBars.ExecuteMso ("EmptyFolder")
  End If
Next i
 
objExpl.SelectFolder olNS.GetDefaultFolder(olFolderInbox)
 
End Sub
 
Sorry, I have no quick solution for you but I would like to point out that in my three Accounts I have different names for the folder of deleted emails. The default is translated in my language will the others are "Trash" and "Trashcan". I need to change (3 times) this line in your macro and relaunch it to have the folders in the other accounts cleared:
Code:
Set deletedItemsFolder = olNS.Folders(i).Folders("Deleted Items")
Maybe your folders are named differently as mine are.
 
Back
Top