Is there anyway to make Outlook set the read email that doesn't have any categories assigned to them back to unread?
2 Answers
Try the following:
Public Sub Mark_Unread_If_No_Category()
Dim objNS As Outlook.NameSpace: Set objNS = GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder: Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim Item As Object
For Each Item In olFolder.Items
If Item.Class = 43 Then ' 43 = an email
Dim oMail As Outlook.MailItem: Set oMail = Item
If oMail.Categories = "" Then
Debug.Print "Marking as unread: " & oMail.Subject
oMail.UnRead = True
oMail.Save
End If
Set oMail = Nothing
End If
DoEvents ' So Outlook doesn't lock up whilst running
Next
Set olFolder = Nothing
Set objNS = Nothing
End Sub
I know that it correctly looks in the inbox and it correctly finds emails without categories (the Debug.Print
confirms this) however I've not checked that those emails become unread.
As a result, you should backup your inbox before you give this a go.
-
Thanks for the answer, how do you set it to just do it on one specific folder or inbox ? Jan 16, 2018 at 4:02
-
Assuming your folder (say "TPS Reports") sits within your inbox, then you should change
objNS.GetDefaultFolder(olFolderInbox)
toobjNS.GetDefaultFolder(olFolderInbox).Folders("TPS Reports")
– RichardJan 16, 2018 at 8:53
This is quite easy. Just create a Custom Search Folder, name it as you like (say, "Not categorized") select required folder(s), specify the Criteria on the Advanced tab as follows:
Field: All Mail Fields -> Categories
Condition: is empty
Click Add to List and then OK, OK.
Now you can select all messages in this folder and mark them all as Unread.