Using Search Folders in Outlook 2007 for GTD

One of my favorite features of Outlook 2007 is Search Folders.  A Search Folder is a dynamic folder, automatically populated based on a query.  For example, a Search Folder can be used to show all email over 1Mb in size.   

Being a GTD (Getting Things Done) addict, I wanted to see if I could use Search Folders to create separate folders for each of my project categories.  For example, if I have an Outlook category called TechEd 2009, wouldn’t it be nice to have a couple of search folders – one to show all of the active tasks associated with that category, the other to show all of the mail filed under that category.

image 

Out of the box however, this is a little difficult to setup – while you can easily create a Search Folder that displays mail relating to a category, in Outlook 2007 you can’t actually create a Search Folder that filters on tasks.  After a little digging, I found out that Search Folders do support the capability of filtering other types of objects, but only querying of mail items are exposed in the Outlook UI.

To overcome this limitation however, we can use a simple macro:

Sub CreateNewSearchFolder()

   Set MyOutlookApplication = Outlook.Application
   SearchSubFolders = True
   Set MapiNamespace = Application.GetNamespace("MAPI")
   Set TasksFolder = MapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Parent
   strS = "’" & TasksFolder.FolderPath & "’"

   Dim folderName As String
   folderName = InputBox("What category would you like to create a search folder for?:", "Category", "")
   Dim objSch As Search
   Dim categoryFilter As String
   categoryFilter = "(""urn:schemas-microsoft-com:office:office#Keywords"" LIKE ‘%" & folderName & "%’)"

   Dim taskFilter As String
   taskFilter = "(""http://schemas.microsoft.com/mapi/proptag/0x0e05001f""= ‘Tasks’ AND ""http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003"" <> 2) OR (NOT(""http://schemas.microsoft.com/mapi/proptag/0×10900003"" IS NULL) AND ""http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003"" <> 2)"
   Dim strTag As String
   strTag = "RecurSearch"

   ‘ Create the tasks folder

   Set objSch = Application.AdvancedSearch(Scope:=strS, Filter:=categoryFilter & " AND (" + taskFilter + ")", _
      SearchSubFolders:=True, Tag:=strTag)
   objSch.Save (folderName)

   ‘ Create the mail folder

   Set objSch = Application.AdvancedSearch(Scope:=strS, Filter:=categoryFilter, _
      SearchSubFolders:=True, Tag:=strTag)
   objSch.Save (folderName & " (Mail)")

End Sub

The above macro will prompt you for a category name and auto-magically create two search folders – one that will display the active tasks assigned to that category, and one that will display all items (both mail and tasks) assigned to that category. 

Your mileage with this may vary (and I’m sure you’ll believe me when I say the above is not officially supported :-)) but I’ve found this very useful to look at active tasks and filed mail for a specific GTD category without leaving the comfort my email folder list.

44 thoughts on “Using Search Folders in Outlook 2007 for GTD

  1. http://

    Perfect, I have been struggling for a while switching between my task view and my email view. This is exactly what I have been looking for. Thanks

    Reply
  2. http://

    i prefer search tools like lookeen,
    isn´t it a bit too complicated and time-wasting to set up search folders?

    -dan-

    Reply
  3. http://

    Hi Simon,

    Thanks so much for this. I also make a shortcut to all my search folders because 1.) you can group shortcuts and 2.) you don’t have to view the default folders. Any chance you could help me with a macro that would do what you have done but also create the corresponding shortcut with the same name as the category? Would much appreciate this.

    Regards,

    Ben
    benjamin.kadlecik@ricardo.com

    Reply
  4. smguest

    Hi Ben,

    Yes, this is pretty easy to do. Create a new function that adds shortcuts:

    Sub AddShortcut(target As String, name As String)
    Dim myOlBar As Outlook.OutlookBarPane
    Dim myolGroup As Outlook.OutlookBarGroup
    Dim myOlShortcuts As Outlook.OutlookBarShortcuts

    Set myOlBar = Application.ActiveExplorer.Panes.item(“OutlookBar”)
    Set myolGroup = myOlBar.Contents.Groups.item(1)
    Set myOlShortcuts = myolGroup.shortcuts
    myOlShortcuts.Add target, name
    End Sub

    Then, add the following line after the objSch.Save lines:

    AddShortcut “outlook:search folders” + folderName, folderName

    This will add a new shortcut item pointing to the search folder. Hope this helps. -Simon

    Reply
  5. http://

    Hi Simon,

    Thanks a lot for this! I think that I can use it for finally getting all my sent/incoming mails and tasks into a single view. I’ve used your script for creating a search folder including the inbox and the to-do list folder but it doesn’t work. I’m not an expert so may be you can give me some clues… This is what I have so far:

    Sub CreateNewSearchFolder()

    Dim objSch As Search
    Dim strS As String
    Dim strTag As String

    strS = “‘Bandeja de entrada’ , ‘To-Do List’”
    strTag = “InboxTasks”
    strF = “urn:schemas:httpmail:importance = 2″
    Set objSch = Application.AdvancedSearch(strS, strF, False, strTag)

    If objSch Is Nothing Then
    MsgBox “Sorry, the search folder could not be created.”
    End If

    objSch.Save (“2DoList”)

    End Sub

    Reply
  6. http://

    Hi Simon,

    Thanks a lot for this! I think that I can use it for finally getting all my sent/incoming mails and tasks into a single view. I’ve used your script for creating a search folder including the inbox and the to-do list folder but it doesn’t work. I’m not an expert so may be you can give me some clues… This is what I have so far:

    Sub CreateNewSearchFolder()

    Dim objSch As Search
    Dim strS As String
    Dim strTag As String

    strS = “‘Bandeja de entrada’ , ‘To-Do List’”
    strTag = “InboxTasks”
    strF = “urn:schemas:httpmail:importance = 2″
    Set objSch = Application.AdvancedSearch(strS, strF, False, strTag)

    If objSch Is Nothing Then
    MsgBox “Sorry, the search folder could not be created.”
    End If

    objSch.Save (“2DoList”)

    End Sub

    Reply
  7. http://

    Suciocerdo:

    What error are you seeing? You need to keep strTag = “RecurSearch”. This is specific to SearchFolders, and not a name that can be changed.

    Thanks.
    -Simon

    Reply
  8. http://

    Simon,

    Thanks for the tip. The syntax seems to be ok now. However, it still doesn’t work. I get a “Can’t find library or project” error that I haven’t been able to correct. After trying to use your code directly, I get the same error. Do you know if I have to activate a specific library for this?

    Thanks again,

    Reply
  9. http://

    hey there, apparantly no one’s replied to Bigdan’s comment. I was asking myself the same question: Why create search folders when I could just as well use a search tool which is way less time-consuming? (@bigdan: I also use lookeen and I think it’s great.it has made working with outlook much easier)

    -jason

    Reply
  10. http://

    @Jason: I find the folder approach more convenient than having to re-search every time, but I guess it’s a question of habit. Also, doing a search containing both mail and tasks in Outlook requires Advanced find, which is definitely more than one click.

    Reply
  11. http://

    Hi Simon, I hope this isn’t to remedeal but…when I copy and paste the macro formula where do I paste it?

    PS I really love all of the helpful tips you have for outlook and GTD!

    Reply
  12. http://

    Jill – in Outlook, press ALT-F11 to bring up the macro editor. Paste the code into ThisOutlookSession and you should be set. You may need to configure the Macro security to get the macros to run correctly on your machine. Hope this helps. -Simon

    Reply
  13. http://

    Hi Simon, This is amazing. Thanks. I was curious how to exclude particular subfolders in your macro, like the Deleted Items and a few others. Thanks again. Greg

    Reply
  14. http://

    Is there a way to leave the Search Folder “open”, so you can edit it from the Outlook UI?
    Now I use a search folder that displays all my unread or flagged mail (with due dates) and this macro is just what I need to add the tasks to that list as well. But I need to edit the Search Folder after it’s created to edit these filters – can that be done?

    Reply
  15. http://

    Jakob – are you looking to edit the title of items in the search folder? What are you looking to change? Thanks.

    Reply
  16. http://

    Hi Simon,
    What I’m looking for, is being able to edit the criteria of the search folder. (right click on search folder and select “Customize this Search Folder…” and then click the button “Criteria…”.
    On Search folders you’ve created yourself this “Criteria” button is enabled… but it’s not in the folders created by your macro or on the standard Outlook folders “For Follow up” and “Unread Mail” (but is is on the folder “Large Mail” funnily enough). Thanks!

    Reply
  17. http://

    Hi Jakob, unfortunately this isn’t possible – as I mention in the introduction of this post, the functionality in the script is not provided by the UI, hence the UI is disabled on folders that the script creates. If you can explain more about what you are trying to do however, we might be able to do it in the code. Thanks.

    Reply
  18. http://

    Can we make a search folder which have global scope .. I mean , Search folder which can have mails from root and archive folders at the same time .. so we can customize view on all mails ..

    plz advice ..

    Bregds/Sunil

    Reply
  19. http://

    Thanks Simon. As I said earlier, I use my “Unread Mail” to get an overview on all outstanding mails (and include the column “Due By” if there is a specific deadline on the mail – I set this myself if the sender has not marked it for follow up). On this view I would like to include the tasks as well, as in your script. But I only want task that has not been completed. So no searching for category names on either mail or tasks – just unread mails and not completed tasks. So basically I will get an overview of all outstanding work in Outlook in one view. Again, thanks for your help Simon!

    Reply
  20. http://

    Jakob, try removing the category filter from the line that creates the search folder. Something like this:

    Set objSch = Application.AdvancedSearch(Scope:=strS, Filter:=”(” + taskFilter + “)”, _
    SearchSubFolders:=True, Tag:=strTag)
    objSch.Save (folderName)

    This will remove the category filter, and display all tasks that need to be completed. For your unread mail you could either create another search folder manually – or it would be a case of working out the filter programmatically (unfortunately the documentation to do this is a little limited). Hope this helps.

    Reply
  21. http://

    Sunil, these two lines control the scope:

    Set TasksFolder = MapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Parent
    strS = “‘” & TasksFolder.FolderPath & “‘”

    I don’t use archive folders, so I can’t test, but you should be able to work out how to point this to an archive / PST folder. I’m not sure whether you can create a single search folder that can have scope across the mailbox and archive PST folders however. Can you do this manually? Thanks.

    Reply
  22. http://

    I find this a great help in managing day to day. I use the flags in 2003 heavily and it would be great if the active search folder also included mail that had a flag set against it. This would give me all the active tasks and emails in one place.
    Anyone out there can help me?

    Reply
  23. Anastassios Evangelou

    Hi Simon,

    I ‘ve tried your macro with success to create a task search folder. The problem is that I am not using the native “IPM.Task” form but instead of it I have created a custom one into personal forms library and a lot of custom fields associated with it. I ‘ve also changed the form associated with Outlook’s native task folder with my “IPM.Task.UNISYSTEMS” so when I post to it Outlook uses my custom task form. Now, even we have managed to create a task search folder my custom form’s fields are not available there. Can you please advice on this?

    B.R.

    Reply
  24. http://

    Jill, right click on the tool bar and select customize. Select the macro from the categories list and drag/drop the macro to the toolbar. Hope this helps. -Simon

    Reply
  25. http://

    BR – Sorry, thought I had already answered. My recommendation would be to pickup a copy of Outlook Spy in order to get the MAPI IDs for the objects/forms you are working with. Once you have this, you’ll need to change the task filter to filter on your forms instead of regular tasks. i.e. replace the IDs in the following code with the ones that Outlook Spy reports.

    Dim taskFilter As String
    taskFilter = “(“”http://schemas.microsoft.com/mapi/proptag/0x0e05001f””= ‘Tasks’ AND “”http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″” <> 2) OR (NOT(“”http://schemas.microsoft.com/mapi/proptag/0×10900003″” IS NULL) AND “”http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″” <> 2)”
    Dim strTag As String
    strTag = “RecurSearch”

    Hope this helps.

    Thanks.
    -Simon

    Reply
  26. http://

    Very nice macro,
    however I want to do a very easy thing. Is there a way to MERGE all my search folders into ONE ? I have a lot of PSTs and consequently one FOLLOW UP for each, but I’d like to merge all of them into one. Do I need macro for this ? could you please help me ?

    Thank you !!

    Reply
  27. http://

    Hi Simon,
    Very nice macro. I’m using it already.
    Now I have a tricky one (for me). I would like to create a Search Folder (anywhere) with the content of other Search Folders in different PST files. Is it possible?
    Please help me.

    Reply
  28. http://

    Great post. Thank you Simon. A couple of follow-up questions:

    1) What would the macro look like for the following criteria:

    Search all email (including dozens of .pst files) based on the following critieria…
    From: Wes
    To: Rich
    Subject includes: ‘forecast’
    Has Attachments: Yes

    2) Where does this macro go in 2007? :)

    Reply
  29. http://

    I like this script! I can see lots of uses for it as a recruiter scanning contacts in my Outlook database with multiple criteria. How easily would it be to include search criteria to find candidates with two categories (ie, regulatory AND quality control)? And to also narrow the results to only include contacts with IL (Illinois) in either their Home Address State or Business Address State? I’ve learned how to modify your script to search for contacts containing one category. Can I easily add additional criteria in the programming section that requires all to be present?

    Reply
  30. Pingback: Mathias Mühlfelder » Blog Archive » Outlook 2007 Aufgaben in Suchordnern anzeigen

  31. Mike

    This worked great on my XP machine, but it won’t run on W7. I get an error on the Set objSch = Application.AdvancedSearch…….. line

    Run-time error -2147024809 Could not complete the operation. One or more parameter values are not valid.

    Probably something in the categoryfilter or taskfilter. Not sure if those schemas got changed in W7

    Reply
    1. Simon Post author

      Very odd – are all your line breaks OK? If it’s complaining about parameters not being valid, maybe one of the underscores went missing?

      Reply
  32. Bruce

    Is there any way to create a search folder for tasks without a catagory assigned? I tried to leave the catagory blank but got

    Run-time error’-2147024809 (80070057)’:

    Could not complete the operation. One or more parameter values are not valid.

    (I often forget to catagorize tasks when I enter them on the smartphone and being able to see them in a similar way as the other search folders would be helpful.)

    This post has become a cornerstone for my GTD setup. Thanks for it.

    Reply
  33. Mike

    I removed all of the breaks. On the line that bombs: Set objSech = Application.AdvancedSearch……..

    My variables are:

    ?strs
    ’Mailbox – John Doe’

    ?categoryfilter
    (“urn:schemas-microsoft-com:office:office#Keywords” LIKE ‘%Stuff%’)

    ?taskfilter
    (“http://schemas.microsoft.com/mapi/proptag/0×0e05001f”= ‘Tasks’ AND “http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″ 2) OR (NOT(“http://schemas.microsoft.com/mapi/proptag/0×10900003″ IS NULL) AND “http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″ 2)

    ?strTag
    RecurSearch

    Not sure if any of this helps.

    Reply
  34. Al

    Hi,
    Thanks for the tip and the vb code!

    I am experiencing the same problem as Mike. I get the same error message as Mike (“Run-time error -2147024809 Could not complete the operation. One or more parameter values are not valid”). I am running Windows 7 and Office 2007 SP2.

    I’d love to have this functionality. Any idea on how to fix it?

    Aslak.

    Reply
  35. Bala

    Hi,
    Asking a question that went unanswered somewhere up there :)

    I use Outlook 2007 in Cached Exchange mode and have a 900MB exchange server mailbox limit. I am required to move my mail to local PSTs if it approaches the limit.

    Is there any way to create a Search folder that either:
    1) Allows me to search my Exchange Inbox as well as my Local PST Inbox or
    2) Contains results of multiple search folders from multiple PSTs and the Exchange Inbox.

    Thanks a lot in advance!

    Bala

    Reply
  36. Ryan Lim

    I am using Outlook 2010 and window 7. I had the same problem with Run-time error’-2147024809 (80070057)’. I spend the whole day on 14/4/2011 to google, read through all the material I can find, read up 2x programming books on outlook I had and came to the conclusion that the error came from

    taskFilter = “(“”http://schemas.microsoft.com/mapi/proptag/0×0e05001f””= ‘Tasks’ AND “”http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″” 2) OR (NOT(“”http://schemas.microsoft.com/mapi/proptag/0×10900003″” IS NULL) AND “”http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″” 2)”

    The most likely cause is the proptag which may have changed. I am NOT too familiar with DASL filters used in the Outlook AdvancedSearch method used, so maybe I was wrong.

    Solution:
    I found that in outlook 2010 you can add a filter tab to the ribbon and add a query by editing the registry. It may also be possible to use the advanced tab when using this filter and then look at the SQL generated. For example, see these two picture and see that the SQL syntax is very similar to thetaskFilter above.

    http://imgur.com/SMTdx

    http://imgur.com/XAaaw

    My Code
    ————-
    I modified the code based on searches at MSDN and simonguest code. This code will only create searchfolder for tasks with category you type in. You can easily modify it to create searchfolder for mails with category too. I am still working on this and when I master the DASL filtes used, I will improve the codes for more power and user friendliness so do check future posts down the line.

    Sub CreateNewSearchFolder()

    ‘Create a New SearchFolder for tasks
    ‘This only work if you paste the code in ThisOutlookSession, if you paste it to Modules, then application and namespace need to be program in

    Dim objSearch As Search
    Dim strFilter As String
    Dim strScope As String
    Dim strTag As String
    Dim strFolderName As String
    Dim strCategoryFilter As String

    strFolderName = InputBox(“What category would you like to create a search folder for?:”, “Category”)
    strCategoryFilter = “(“”urn:schemas-microsoft-com:office:office#Keywords”” LIKE ‘%” & strFolderName & “%’)”

    strScope = “‘” & Application.Session.GetDefaultFolder(olFolderTasks).FolderPath & “‘”

    strFilter = “(“”http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/81010003″” = 0)”
    strTag = “RecurSearch”

    Set objSearch = Application.AdvancedSearch(Scope:=strScope, Filter:=strCategoryFilter & ” AND (” + strFilter + “)”, SearchSubFolders:=True, Tag:=strTag)

    If objSearch Is Nothing Then
    MsgBox “Sorry, the search folder could not be created.”
    End If

    objSearch.Save (strFolderName)

    End Sub

    Reply
  37. Pingback: Solution to using Outlook 2010 for GTD « The Trusted Adviser

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>