Outlook macro to create search folder with mail categories as criteria

Status
Not open for further replies.

Ambiorix

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hi there,
Since 2010, my workflow is based on the principle of Control Your Day.
Main tools are categories and search folders. I have improved the process by adding my own VBAs to add next actions to the context folder.
The last missing piece I can not get working is the ability to create a search folder based on the assigned categories of a mail.
In other words, when you select an email with categories “Customer” & “BMW” and run the macro, it would create a search folder with “customer” & “BMW” as its criteria.
Thanks a lot in advance and let me know if you want to know more about the Control Your Day way of working!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I have a macro for to/from sender, it should work to change it to categories.
How to Create an Outlook Search Folder using VBA

You won't need to use the propertyaccessors part - replace the sql string with the proper search string.

Code:
("urn:schemas-microsoft-com:office:office#Keywords" = 'cat1' AND "urn:schemas-microsoft-com:office:office#Keywords" = 'cat2')

to split the categories, we'll steal a bit of code from Macro to Add or Remove a Category


This should work to replace the propertyaccessors part - the folder is named for the category string - which is exactly how it shows up on the selected message.


Code:
 arr = Split(oMail.Categories, ",")
    If UBound(arr) >= 0 Then

' Check for Category
    For i = 0 To UBound(arr)
    strCat1 = arr(0)
    strCat2 = arr(1)
    Next
    End If


Dim strDASLFilter As String


strDASLFilter = "(" & """urn:schemas-microsoft-com:office:office#Keywords""" & "= '" & strCat1 & "' AND" & """urn:schemas-microsoft-com:office:office#Keywords""" & "= '" & strCat2 & "')"
Debug.Print strDASLFilter

Dim strScope As String
strScope = "'Inbox', 'Sent Items'"
    
Dim objSearch As Search
Set objSearch = Application.AdvancedSearch(Scope:=strScope, Filter:=strDASLFilter, SearchSubFolders:=True, Tag:="SearchFolder")

'Save the search results to a searchfolder
objSearch.Save (oMail.Categories)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I updated the search folder article with a macro for categories.

For the second category, you need to use trim, otherwise there is a leading space and it's not found.
strCat2 = Trim(arr(1))
 

Ambiorix

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Dear Diane,
Many thanks for your prompt support, it works like a charm!
Warm greetings from Bangkok,
Maarten
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
N How Can I create an Outlook Macro to import calendar? Outlook VBA and Custom Forms 1
S How to create a macro to insert a signature in Outlook 2007 Outlook VBA and Custom Forms 1
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 19
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
R Macro Schedule every day in Outlook Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
V Outlook Macro to show Flagged messages Outlook VBA and Custom Forms 2
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
C Outlook Subject Line Macro Outlook VBA and Custom Forms 0
D Macro sending outlook template from Excel list Outlook VBA and Custom Forms 6
P Macro to attach a file in a shared Outlook draft folder Outlook VBA and Custom Forms 2
R Macro to check file name with outlook address book Outlook VBA and Custom Forms 0
Diane Poremsky Use a macro to copy data in Outlook email to Excel workbook New Slipstick.com Articles 0
W macro to export outlook emails to excel Outlook VBA and Custom Forms 6
J Outlook Macro to Update Sharepoint Excel File Using Outlook 1
Patrick van Berkel Best way to share (and keep up-to-date) Macro's in Outlook 2010 Outlook VBA and Custom Forms 6
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
L Outlook 2007 - Macro Re Search Using Outlook 16
L Outlook 2007 Macro to Contact From a Field Using Outlook 3
A newb outlook macro help Outlook VBA and Custom Forms 1
Diane Poremsky Macro to Bulk Import Contacts and vCards into Outlook New Slipstick.com Articles 0
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
S Macro in an excel for outlook. Outlook VBA and Custom Forms 2
A Outlook Macro Causing Excel Error Outlook VBA and Custom Forms 0
Diane Poremsky Use a macro to copy data in Outlook email to Excel workbook New Slipstick.com Articles 0
S Outlook Macro Reply to a message Outlook VBA and Custom Forms 1
Diane Poremsky Macro to Bulk Import vCards into Outlook New Slipstick.com Articles 0
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
A Macro to Copy Data from Outlook to Excel Spreadsheet Using Outlook 2
P Outlook Macro sends information to Excel Using Outlook 1
P Outlook Macro keeps running for the same messagage Using Outlook 2
B Looking for Outlook 2013 update for Send Drafts Macro Using Outlook 4
J VBS Script (macro) for word to open Outlook template. Outlook VBA and Custom Forms 2
S Macro for Reply All in 2013 Outlook Outlook VBA and Custom Forms 10
L Outlook 2007 Macro Save Contact Using Outlook 10
Aussie Looking for Outlook macro to Copy Recipient Names into Email Body Outlook VBA and Custom Forms 3
H Outlook Macro Using Outlook 1

Similar threads

Top