Macro to set the category of Deleted Item?

4DaddyT

New Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
#1
I have the following macro to search all my email accounts but I'd like to exclude the Deleted Items folder. I thought there might be a way to filter it in my text search statement but wasn't successful. After a couple hours I thought I might be able to do it by setting a category and filtering not to include that category. I must be over looking something but this seems like overkill. So continuing with this category thought, I would like to create a macro to set the category of items that arrive in the Deleted Items folder to 'Deleted' then I would just add "& NOT category: (Deleted)" to my txtSearch variable. My current macro below...

Sub LastSevenDays()
Dim myolApp As New Outlook.Application
Dim tDate As Date
tDate = Now - 7

txtSearch = "received: (" & Format(tDate, "mm/dd/yyyy") & ".." & Format(Now, "mm/dd/yyyy") & ")"
myolApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myolApp = Nothing
End Sub


Any assistance would be greatly appreciated. Thank you
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#2
Do you have the option set to include the deleted items in all items search? That should skip the deleted items in the macro too.

if you need that enabled for all except this search add folderpath: NOT deleted to the tstSearch string.
 
Last edited:

4DaddyT

New Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
#3
I have the option 'Include messages from Deleted items folder in each data file when searching All Items' uncheck and the query was still bringing back those deleted items. I added 'folderpath: NOT deleted' to my txtSearch variable and that solved my issue. Thank you Diane
 
Top