You can edit the Flag to Follow up field text each time you flag a message, but you can't save the changes permanently, or even temporarily in an MRU list. However, you can use VBA to set flags, which will allow you to save custom Flag to text, as well as custom reminder times and start or due dates.
This code sample sets a flag to "Call display-name", with a due date in 3 days and a reminder set for 2 days.
To create the macro, open the VBA editor using Alt+F11. Right click on Project1 and choose Insert > Module. Paste the macro into the module and edit as needed.
You'll also need the GetCurrentItem function from Work with an open or selected Outlook item. Paste it in the module following this macro.
For more information on using VBA, see How to use the VBA Editor.
To use the macro, open or select a message and run the macro.
Public Sub SetCustomFlag() Dim objMsg As Object ' GetCurrent Item function is athttp://slipstick.me/e8mio Set objMsg = GetCurrentItem() With objMsg ' due this week flag .MarkAsTask olMarkThisWeek ' sets a specific due date .TaskDueDate = Now + 3 .FlagRequest = "Call " & objMsg.SenderName .ReminderSet = True .ReminderTime = Now + 2 .Save End With Set objMsg = Nothing End Sub
Note: if you don't include the .MarkAsTask line, the flag will be the 'people flag'. If you use olMarkToday and set the due date for next week, it's converted to a 'next week' flag.
Flag messages after sending
This macro will ask if you want to flag a message after sending it. It waits for a message to hit the Sent folder then asks if you want to flag it.
Because this is an Application_Startup macro, you need to click in Application_Startup code and click Run to test it.
Option Explicit Private WithEvents olSentItems As Items Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.Session ' instantiate objects declared WithEvents Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items Set objNS = Nothing End Sub Private Sub olSentItems_ItemAdd(ByVal Item As Object) On Error Resume Next Dim prompt As String prompt$ = "Do you want to flag this message for followup?" If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then With Item .MarkAsTask olMarkThisWeek ' sets a due date in 3 days .TaskDueDate = Now + 3 .ReminderSet = True .ReminderTime = Now + 2 .Save End With End If End Sub
No Message Box: Say Yes Before Sending
This variation of the above macro uses a button on the ribbon to click Yes rather than the message box as the message is sent.
Add the SayYes macro to the message form ribbon and click it before sending any message that you want to flag for follow-up.
Option Explicit Dim SetFlag Private WithEvents olSentItems As Items Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.Session ' instantiate objects declared WithEvents Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items Set objNS = Nothing End Sub Private Sub olSentItems_ItemAdd(ByVal Item As Object) On Error Resume Next Dim prompt As String If SetFlag = vbYes Then With Item .MarkAsTask olMarkThisWeek ' sets a due date in 3 days .TaskDueDate = Now + 3 .ReminderSet = True .ReminderTime = Now + 2 .Save End With End If SetFlag = vbNo End Sub Sub SayYes() SetFlag = vbYes End Sub
Select a Due Date
The macro samples above use a predefined date for the flag (and/or reminder). If you want to choose your own date, you'll need to use an InputBox and enter either 'a days from now' value or a date (in any valid short date format).
To enter a number for days from now, use this code, with the DIM statement at the top, the InputBox before the With Item line, and replace the TaskDueDate line with the one below.
Dim countDays As Long countDays = InputBox("How many days from now?") .TaskDueDate = countDays
To enter a specific date, use this code, with the DIM statement at the top, the InputBox before the With Item line, and replace the TaskDueDate line with the one below. In this code, any valid short date format should work: 4/1, 4/1/17, or 4/1/2017.
Dim RemindMeOn As Date RemindMeOn = InputBox("Enter the reminder date in any valid short date (m/d/y) format") .TaskDueDate = RemindMeOn
Flag all messages as they arrive
If you want to flag all messages as they arrive, you can use an ItemAdd macro, or use a rule with a run a script macro. In this example, I have an ItemAdd macro. You could use an If statement to restrict which messages are flagged, or convert it to a run a script macro and use a rule to filter the messages.
To use this code, paste it into ThisOutlookSession, click in the Application_Startup macro and click the Run button. Don't forget to set your macro security to low during testing then use SelfCert to sign it when you are satisfied it works as expected.
Option Explicit Private WithEvents olItem As Items Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.Session ' instantiate objects declared WithEvents Set olItem = objNS.GetDefaultFolder(olFolderInbox).Items Set objNS = Nothing End Sub Private Sub olItem_ItemAdd(ByVal Item As Object) On Error Resume Next With Item .MarkAsTask olMarkThisWeek ' sets a due date in 24 hours .TaskDueDate = Now + 1 .ReminderSet = True .ReminderTime = Now + 1 .Save End With End Sub
Run a Script rule to Flag Messages
To use the macro in run a script rule, use the following code sample.
Public Sub FlagMessage(Item As Outlook.MailItem) On Error Resume Next With Item .MarkAsTask olMarkThisWeek ' sets a due date in 24 hours .TaskDueDate = Now + 1 .ReminderSet = True .ReminderTime = Now + 1 .Save End With End Sub
See Run a Script rules for more information on using Run a Script rules.
Mark Flags Completed and Remove Categories
Use this macro to mark flagged message complete and remove any categories assigned to the message.
Option Explicit Public Sub DoSomethingSelection() Dim Session As Outlook.NameSpace Dim currentExplorer As Explorer Dim Selection As Selection Dim obj As MailItem Set currentExplorer = Application.ActiveExplorer Set Selection = currentExplorer.Selection For Each obj In Selection With obj .Categories = "" .FlagStatus = olFlagComplete .Save End With Next Set Session = Nothing Set currentExplorer = Nothing Set obj = Nothing Set Selection = Nothing End Sub
Outlook 2003
If you are using Outlook 2003, you need to edit the code a little, as Outlook 2003 uses colored flags.
Allowable Flag colors | |
---|---|
olNoFlagIcon | olPurpleFlagIcon |
olOrangeFlagIcon | olGreenFlagIcon |
olYellowFlagIcon | olBlueFlagIcon |
olRedFlagIcon |
Public Sub SetCustomFlag() Dim objMsg As Object ' GetCurrent Item function is athttp://slipstick.me/e8mio Set objMsg = GetCurrentItem() With objMsg .FlagIcon olPurpleFlagIcon .FlagDueBy = Now + 3 .FlagRequest = "Call " & objMsg.SenderName .ReminderSet = True .ReminderTime = Now + 2 .Save End With Set objMsg = Nothing End Sub
How to use macros
First: You need to have macro security set to low during testing. The macros will not work otherwise.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s 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.
Some macros need to be in ThisOutlookSession, others go into a module or can be placed in either ThisOutlookSession or a module. The instructions are below.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
If you are told to put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
If you are told to put the macro code in ThisOutlookSession:
- Expand Project1 and double click on ThisOutlookSession.
- Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)
More information as well as screenshots are at How to use the VBA Editor
When I paste the code into the module, it gives a compilation error as per the image attached. Any idea hoe to solve this? Thanks!
Hi Diane - is it possible to capture more than one outgoing email? I have a 2 min delay rule in place. If I send two emails within that 2 min period (both to be flagged) the variable is wiped/cleared upon the first hitting sent box so the second doesnt get flagged...
Any thoughts?
Hi Diane. Thank you kindly for the code. There is a bit of a bug where it will error if you try to set the TaskDueDate = 1. The TaskStartDate defaults to 2 days out, so you need to first set TaskStartDate to the same thing as your TaskDueDate. Otherwise the due date is before the start date and it errors. That took me a while to figure out, so I wanted to share the fix.
Diane,
I've used these macro's for years and appreciate everything you've posted here. I'm trying to get the macro that flags sent emails for follow-up to work with multiple email accounts in outlook, but as you've mentioned before it only works with the defaults.
I've been trying to incorporate the code from the "working with VBA and non-default folders" post and can make it work with the secondary email account, but then it stops functioning with the default account.
Any assistance you can provide is appreciated.
Is there a way to set a flag Orange Category and Flag for follow up just before you send the email. The example above is for after you sent an email.
There is flag ? button and change category just before we press send.
It is possible to set a category before sending - this will send it to the recipient too (they may or may not see it, depending on the mail client and if rules or their server removes it).
It's better to set it using a macro you run manually, so you can choose whether to add it.
I have a macro here somewhere that does it - I will update this article with it.
Hi Diane,
Hope you are doing good:)
I have an situation in outlook any emails which comes in to the share mail inbox i want it to automatically set up a flag for 2 days, i tried using the code which you have written looks like it is not working in shared mail box, can you please help me on this.
The macro in your question should work on any message in any folder in your profile - you need the GetCurrent Item function from http://slipstick.me/e8mio
if its a shared exchange mailbox and you want to do it automatically using an itemadd macro, you need to use the shared mailbox code at
Working with VBA and non-default Outlook Folders (slipstick.com)
(I will add an itemadd version to this page)
I send mail from excel and this code not working in excel VBA.
What code I need for flag in excel vba?
this the itemsend macros should do it,
https://www.slipstick.com/developer/code-samples/set-flag-follow-up-using-vba/#flag
Hi, thanks for this. It is very helpful.
I just have a question, is it possible to automatically set the reminder if the Subject contains a keyword?
For example i send an email and instead of the dialog box, it would set me a reminder if the subject contains "FOLLOW UP"
You can do that using a rule - if you have reminders set for tasks with due dates. Or you can use a rule and run a script macro to set the reminder.