Welcome to Sign in | Join | Help

Browse by Archive:




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/0x10900003"" 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.

Comments

Dave Smyth

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
# March 11, 2009 3:39 PM

Bigdan

i prefer search tools like lookeen, isn´t it a bit too complicated and time-wasting to set up search folders? -dan-
# March 12, 2009 12:45 PM

Ben Kadlecik

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
# March 31, 2009 6:40 AM

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

# March 31, 2009 1:34 PM

suciocerdo

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
# April 3, 2009 3:13 PM

smguest

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

# April 3, 2009 7:07 PM

suciocerdo

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,
# April 5, 2009 4:08 PM

Jason

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
# April 5, 2009 4:26 PM

smguest

@Suciocerdo:  What version of Office are you using?  Do you get an error on a specific line?

# April 5, 2009 11:46 PM

smguest

@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.

# April 5, 2009 11:48 PM

suciocerdo

Hi Simon, It stops at: Set MyOutlookApplication = Outlook.Application My office version is 2007
# April 6, 2009 8:12 AM

Jill

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!
# April 16, 2009 1:06 AM

smguest

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

# April 16, 2009 11:42 AM

Greg

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
# April 19, 2009 11:42 PM

Jakob Larsen

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?
# April 21, 2009 9:30 AM

smguest

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

# April 21, 2009 10:46 AM

Jakob Larsen

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!
# April 22, 2009 2:46 AM

smguest

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.

# April 22, 2009 2:21 PM

Sunil

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
# April 23, 2009 12:35 AM

Jakob Larsen

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!
# April 23, 2009 3:15 AM

smguest

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.

# April 23, 2009 11:03 AM

smguest

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.

# April 23, 2009 11:07 AM

John H

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?
# April 27, 2009 2:52 AM

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.
# May 1, 2009 3:00 AM

smguest

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

# May 7, 2009 7:30 PM

Anastassios Evangelou

Hi Simon, Can you be of any help with my initial request? B.R.
# May 22, 2009 9:25 AM

smguest

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/0x10900003"" 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
# May 22, 2009 11:30 AM

Guille

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 !!
# June 2, 2009 9:42 AM

GUILLE

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.
# June 3, 2009 5:02 AM

Wes

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? :)
# June 11, 2009 1:25 PM

Michael

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?
# August 20, 2009 10:05 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS