This macro is the result of a question from a "Getting Things Done" user who wanted a better way to manage tasks on his smartphone.
I use the GTD method and I’ve found that assigning categories doesn’t work for me, one reason is I like to sync the tasks to my iPhone. When you just assign categories and dump everything in one big bucket you have to constantly expand and collapse your views to isolate the right group – lots of clicking and mouse moving. I want to select a message from my inbox – then click on a macro button and have it copied to the appropriate task folder – Do It Today, Deferred, etc. It would look like just like the buttons in the Quick Steps, but unfortunately they just assign the category. I found Create a Task from an Email using a Rule but need help making it work.
Copy the following code block, one copy for each Task folder, and replace the Sub name and folder name (in tFolder) with the name of the folder it will apply to.
Sub TasksFoldername() tFolder = "Old Tasks" CreateTasks End Sub
Create QAT or ribbon buttons for the folder macros. To do this, go to File, Options, Customize Ribbon (or Quick Access Toolbar). In Choose commands from, select Macros. Select the folder macros and click the Add button to add them to the QAT or a ribbon. (If using the ribbon, you need to add a New Group first.)
Tip: if you use the QAT, you can assign keyboard shortcuts to the macros.
Create tasks from email
To use, you need the GetCurrentItem function from Outlook VBA: work with open item or selected item. This will allow the code to work with open or selected messages.
Public tFolder As String Private Sub CreateTasks() Dim Ns As Outlook.NameSpace Dim olTask As Outlook.TaskItem Dim Item As Outlook.mailItem Set Ns = Application.GetNamespace("MAPI") ' Get Function athttp://slipstick.me/e8mio Set Item = GetCurrentItem() Set taskFolder = Ns.GetDefaultFolder(olFolderTasks).Folders(tFolder) Set olTask = taskFolder.Items.Add(olTaskItem) With olTask .Subject = Item.Subject .Attachments.Add Item .Body = Item.Body .DueDate = Now + 1 .Save .Display 'show the task to add notes End With Set Ns = Nothing End Sub ' create one macro for Tasks each folder ' add to ribbon or QAT button Sub TasksFoldername1() tFolder = "My Tasks" CreateTasks End Sub Sub TasksFoldername2() tFolder = "Old Tasks" CreateTasks End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.
The macros on this page should be placed in a module.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor