How to Auto Empty “Junk E-mail” Folder When Exiting Outlook

Some users hope that Outlook can automatically empty “Junk E-mail” folder when exiting Outlook. Though there isn’t such a feature in Outlook, it still can be realized via VBA.

Perhaps you have known that Outlook has an inbuilt feature which is able to auto empty the “Deleted Items” folders when you exit your Outlook. Likewise, you may desire to acquire a similar function, namely auto emptying “Junk E-mail” folder when exiting Outlook. Although Outlook doesn’t provide such a capacity, you still can generate it with VBA. Here we will guide you to realize it in detail.

Auto Empty "Junk E-mail" Folder When Exiting Outlook

Auto Empty “Junk E-mail” Folder When Exiting Outlook

  1. For a start, launch your Outlook program.
  2. Then press “Alt + F11” key buttons to access Outlook VBA editor.
  3. In the emerging “Microsoft Visual Basic for Applications” window, you ought to locate and open the “ThisOutlookSession” project.
  4. Subsequently, you need to copy the following VBA code into this project.
Private Sub Application_Quit()
    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
           'Delete them
        End If
    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
        End If
    'Prompt You
    MsgBox Chr(34) & "Junk Email" & Chr(34) & " Folder Emptied!", vbExclamation + vbOKOnly
End Sub

VBA Code - Auto Empty "Junk E-mail" Folder When Exiting Outlook

  1. After that, you need to assign a digital certificate to this new macro.
  • First hit the “Tools” button.
  • Then choose “Digital Signatures” option from the drop down menu.
  • Next follow the onscreen instructions to accomplish it.
  1. Later change your Outlook macro settings to enable signed VBA projects.
  2. Ultimately, restart your Outlook to activate this new macro.
  3. From now on, every time when you exit Outlook, the “Junk E-mail” folder will be emptied automatically. And you will get a message like the image below:Junk Email Folder Emptied

Effective Measures to Prevent Outlook Crashes

If you’ve utilized Outlook for decades, you must have ever encountered a variety of errors. Also, with time going by, your Outlook will tend to crash and Outlook data file will be prone to corruption. Therefore, in order to prevent Outlook data loss, you’d better make some precautions, including backing up PST file, getting hold of a potent Outlook repair tool, like DataNumen Outlook Repair. It is highly recommended due to its expertise in PST fix.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf fix and outlook repair software products. For more information visit

Leave a Reply

Your email address will not be published. Required fields are marked *