Remove Numbers Beside Junk Mail and Deleted Items Folders

I don't like that the Junk Folder always shows a number beside it. I was searching last week for a way to turn it off, and the best I found was to change the Properties to "Show number of unread items" and then mark all as "Read". This was unsatisfactory for me, as marking as Read is a manual process - I want it to be automatic, and so did many other people posting on forums elsewhere. As an aside, I also find it annoying for numbers to show up by the Deleted items folder. In my brain, a number beside a folder screams "This is an unfinished task!". I just want it to go away and stay away.

I've come up with a method to accomplish this in VBA. As an aside, I also find it annoying for numbers to show up by the Deleted items folder. The steps are as follows:

1. Copy-Past the code below in to "ThisOutlookSession".

2. Create a rule. Apply the rule to "All emails I receive" and select "Run a Script". Select the "JunkReadOnReceive" script.

3. Right-click on the Junk folder and click Properties. Select the option "Show Total Number of unread items." Click OK.

4. Go to the Deleted Items Folder properties and ensure "Show total number of unread items" is selected. It should be already. Click OK.

5. Restart Outlook.

It is now effectively impossible for any email in either the Deleted Items Folder or the Junk Mail Folder to ever be marked as Read, and thus the folders should never have a number beside them. (Strictly speaking, it seems Outlook does not apply rules to mail that is sent directly to Junk (via Blocked Sender or auto filtering). Thus, if you receive an item that is sent directly to Junk, it will put a number beside the folder. But the moment you click on any email or receive any other email, it will automatically remove the number. I can live with this.) 

I am not a programmer. The VBA code is pieced together from various places around the web, and by trial-and-error. If anyone would like to offer more efficient code, please do.

I hope people find this helpful. Please comment with thoughts.

Code follows below this line. Copy-paste everything.

'define variables on startup

Dim WithEvents g_DelFolder As Outlook.Items
Dim WithEvents g_JunkFolder As Outlook.Items
Dim WithEvents myOlExp As Outlook.Explorer

'release variables on quit

Private Sub Application_Quit()
Set g_DelFolder = Nothing
Set g_JunkFolder = Nothing
End Sub

'Set variable values

Private Sub Application_Startup()
Set g_DelFolder = Session.GetDefaultFolder(olFolderDeletedItems).Items
Set g_JunkFolder = Session.GetDefaultFolder(olFolderJunk).Items
Set myOlExp = Application.ActiveExplorer
End Sub

'If an item is deleted, mark it Read.

Private Sub g_DelFolder_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub

'Call JunkRead sub (uses 'Fake' input because Outlook Rules requires it). Function input does nothing and returns nothging.
'Note, I couldn't get the above code to work for Junk Email, because Outlook sees sending items to Junk Mail as "Block Sender", and not "Item Add".
'I couldn't find an Outlook event for "Block Sender". That's why I created the SelectionChange Event Handlers below.

Sub JunkReadOnReceive(Fake As Outlook.MailItem)

JunkRead

End Sub

'Call JunkRead and DelRead upon each selection change (effectively eliminates the possiblility of any items in either Junk or Deleted Items to be marked UnRead)

Private Sub myOlExp_SelectionChange()

 JunkRead

 'Calling DelRead isn't strictly necessary. The above ItemAdd handler will always ensure anything that is deleted is marked read.
 'Calling it here will prevent anything in the delete folder from being marked unread in the future.
 DelRead

End Sub

'Checks whether any unread items exist in the Junk folder and marks them as read.

Private Sub JunkRead()

Dim objJunk As Outlook.MAPIFolder
Dim objOutlook As Object, objnSpace As Object, objMessage As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objJunk = objnSpace.GetDefaultFolder(olFolderJunk)

For Each objMessage In objJunk.Items
    If objMessage.UnRead = True Then
        objMessage.UnRead = False
    End If
Next

Set objOutlook = Nothing
Set objnSpace = Nothing
Set objJunk = Nothing

End Sub

'Checks whether any unread items exist in the Deleted Items folder and marks them as read.

Private Sub DelRead()

Dim objDel As Outlook.MAPIFolder
Dim objOutlook As Object, objnSpace As Object, objMessage As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objDel = objnSpace.GetDefaultFolder(olFolderDeletedItems)

For Each objMessage In objDel.Items
    If objMessage.UnRead = True Then
        objMessage.UnRead = False
    End If
Next

Set objOutlook = Nothing
Set objnSpace = Nothing
Set objDel = Nothing

End Sub

Was this discussion helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this discussion?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this discussion?

Thanks for your feedback.

Personally I only check these folders weekly, and in any case they are not visible unless I scroll down the folder listing, so its nothing that would perturb me
Contributor since 2006
Currently win11 Pro & O365 Bus, multiple devices

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The folders are not far enough down my list to be hidden. 

Also, I have an "All Mail" search folder in my Favorites that includes Deleted Items (but not Junk). I need this folder because I have to keep track of my billable hours. An "All Mail" search folder is helpful when I failed to record my time and I need to ask the question "What did I do on Tuesday?" I can go back and check what all I worked on that day (a lot of my work involves email).  Unread numbers show up by that folder.

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Discussion Info


Last updated March 15, 2024 Views 6,437 Applies to: