Hi,
I have this code to clear spamfolder in the default account but I would like to adapt the code so it works for multiple accounts, not only the default one.
Thanks in advance.
I have this code to clear spamfolder in the default account but I would like to adapt the code so it works for multiple accounts, not only the default one.
Thanks in advance.
Code:
Sub del()
Dim objJunkFolder As Outlook.Folder
Dim i As Long
Dim objMail As Outlook.MailItem
Dim objDeletedFolder As Outlook.Folder
Dim objItem As Object
Dim objProperty As Outlook.UserProperty
Set objJunkFolder = Outlook.Application.Session.GetDefaultFolder(olFolderJunk)
For i = objJunkFolder.Items.Count To 1 Step -1
If objJunkFolder.Items(i).Class = olMail Then
Set objMail = objJunkFolder.Items(i)
'Add the specific property to each junk email
objMail.UserProperties.Add "Delete", olText
objMail.Save
'Delete them
objMail.Delete
End If
Next
Set objDeletedFolder = Application.Session.GetDefaultFolder(olFolderDeletedItems)
For Each objItem In objDeletedFolder.Items
'Find out the junk emails in the "Deleted Items" folder
Set objProperty = objItem.UserProperties.Find("Delete")
If TypeName(objProperty) <> "Nothing" Then
'Permanently delete them
objItem.Delete
End If
Next
'Prompt You
MsgBox Chr(34) & "Ongewenste mail" & Chr(34) & " Folder geledigd !", vbExclamation + vbOKOnly
End Sub