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