• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Flag for Follow up the Next Business Day

Slipstick Systems

› Developer › Flag for Follow up the Next Business Day

Last reviewed on August 6, 2018     6 Comments

Every email which need follow-up is flagged in order of importance with today, tomorrow, this week or next week. Unfortunately however, the tomorrow flag is not usable on friday because the reminder is then set to Saturday although I have excluded both Saturday and Sunday in my work week set in the calendar options.

While Outlook doesn't have a function built in to skip weekends or holidays, you can do it using a set of macros. I have a function that can skip weekends and dates of All Day Events on your calendar that are marked Busy, Tentative, Out of Office, or Working Elsewhere.

In this example, I have Monday and Tuesday marked as Busy, so the flag is moved to Wednesday.
A flag for tomorrow moves to the next business day

Because this runs when you flag a message, you need to put it in ThisOutlookSession.

If your weekends (or days off) are not Saturday and Sunday, you can change the Select Case as needed.

Dim strAllDayOOF As String 
Public WithEvents OlItems As Outlook.Items 

Public Sub Initialize_handler()
   Set OlItems = Application.GetNamespace("MAPI"). _ 
        GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub OlItems_ItemChange(ByVal Item As Object) 

If Item.IsMarkedAsTask = True Then 
If Item.TaskDueDate = Date + 1 Then 
 startDate = NextWeekDaySeries(Date, 1) 
  
 With Item 
    .MarkAsTask olMarkNoDate 
    .TaskStartDate = startDate 
    .TaskDueDate = startDate 
    .ReminderSet = True 
    .ReminderTime = startDate 
    .Save 
 End With 
       
End If
    
End If

End Sub

Private Function NextWeekDaySeries(dateFrom As Date, _
    Optional daysAhead As Long = 1) As Date
  Dim currentDate As Date
  Dim startDate As Date
GetHolidaysOOF
  ' convert neg to pos
  If daysAhead < 0 Then
    daysAhead = Abs(daysAhead)
  End If
 
  ' determine next date
  currentDate = dateFrom
  startDate = DateAdd("d", daysAhead, currentDate)
 
Dim arrHolidays  As Variant
' To be included, holidays need to be marked with a busy state, not Free
arrHolidays = Split(strAllDayOOF, ",")

' Test the date for multiple days off, covers Monday holidays
Dim sameDate As Date
sameDate = Date
Do Until sameDate = startDate + 1
' Go through the array and look for a match, then do something
For i = LBound(arrHolidays) To UBound(arrHolidays)
Debug.Print arrHolidays(i)
If InStr(startDate, arrHolidays(i)) Then startDate = DateAdd("d", 1, startDate)

  Select Case Weekday(startDate, vbUseSystemDayOfWeek)
  Case vbSunday
    startDate = DateAdd("d", 1, startDate)
  Case vbSaturday
    startDate = DateAdd("d", 2, startDate)
  End Select

Next i
sameDate = sameDate + 1
Debug.Print sameDate, startDate

Loop
  NextWeekDaySeries = CDate(startDate)
 
End Function

Sub GetHolidaysOOF()
' Check for all day events on calendar
'  marked busy/off/tentative
'  skips recurring events
' To be included, holidays need to be marked with a busy state, not Free

   Dim CalItems As Outlook.Items
   Dim ResItems As Outlook.Items
   Dim sFilter As String
   Dim iNumRestricted As Integer
   Dim itm As Object
 
   ' Use the selected calendar folder
   Set CalFolder = Session.GetDefaultFolder(olFolderCalendar)
   Set CalItems = CalFolder.Items

   ' Sort all of the appointments based on the start time
   CalItems.Sort "[Start]"
   CalItems.IncludeRecurrences = False
  
   ' Set dates
   sFilter = "[Start] >= '" & Date & "' And [AllDayEvent] = 'True' And [BusyStatus] <> '0' AND [IsRecurring] = 'False'"

   Set ResItems = CalItems.Restrict(sFilter)

   iNumRestricted = 0

   'Loop through the items in the collection.
   For Each itm In ResItems
      iNumRestricted = iNumRestricted + 1
      Debug.Print Format(itm.Start, "m/d/yyyy")
 ' Create list of dates
  strAllDayOOF = strAllDayOOF & Format(itm.Start, "m/d/yyyy") & ","
   Next
   
 ' clean the string for the array
strAllDayOOF = Left(strAllDayOOF, Len(strAllDayOOF) - 1)

   Set ResItems = Nothing
   Set CalItems = Nothing
   Set CalFolder = Nothing
End Sub

How to use the Macro

First: You will need macro security set to low during testing.

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, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

When you are told to put the macro code in ThisOutlookSession:

  1. Expand Project1 and double click on ThisOutlookSession.
  2. 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

Flag for Follow up the Next Business Day was last modified: August 6th, 2018 by Diane Poremsky

Related Posts:

  • One (very justified) complaint about Outlook recurrence patterns is th
    Create Outlook appointments for every nn workday
  • Create a Series of Tasks using VBA
  • How to set a flag to follow up using VBA
  • Use VBA to Email Tomorrow's Agenda

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
6 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Ivan Grigorov
March 5, 2021 6:50 am

A very helpful code, just what I needed.
Just wanted to post a couple of fixes that I needed in order to make it work:

  • @guest_206001 's issue below is caused by the line

strAllDayOOF = Left(strAllDayOOF, Len(strAllDayOOF) - 1)
If you've got no future all-day "Busy" events (as in my case), the strAllDayOOF variable will be empty and VBA throws an error. So I've put it under an If:

If Len(strAllDayOOF) &gt; 0 Then
    strAllDayOOF = Left(strAllDayOOF, Len(strAllDayOOF) - 1)
End If

  • Regarding the regional settings (I'm in EU too), the function Weekday(startDate, vbUseSystemDayOfWeek) doesn't work well, because it returns 6 for Saturday for me, while vbSaturday is 7. So the Select Case needs to be just:

Select Case Weekday(startDate)

Last edited 4 years ago by Ivan Grigorov
0
0
Reply
Peter Hawkes
April 21, 2017 2:37 am

On restart I get an error;

Highlighted in Code Window: WithEvents OlItems As Outlook.Items

In a dialog box: Compile Error: Invalid attribute in Sub or Function

0
0
Reply
Diane Poremsky
Author
Reply to  Peter Hawkes
April 22, 2017 5:41 am

is it in thisoutlooksession?

0
0
Reply
Phil
April 20, 2017 7:14 am

Hello Diane,

I followed your instructions but I don't seem to get it to work.
I copied the macro to my ThisOutlookSession, restarted Outlook and enabled macro's but as from there it is unclear how to get it to work.

I understood that it would run whenever a message or task is flagged but I tried every flag type and it does not take all day events into account. I also tried to run the macro from the developer tab but same result, the macro can be run but nothing happens.

I did notice in the macro that it is based on a US region whil I'm in Europe, for example in the line Debug.Print Format(itm.Start, "m/d/yyyy") which I changed to Debug.Print Format(itm.Start, "d/m/yyyy").
Can this have an impact and would the above change in the code be correct ?

Can you provide me some more info on how to a apply this macro to the flags ?

Thank you in advance !

1
-1
Reply
Phil
April 19, 2017 6:15 am

Hello Diane,

Apologies for my late reply but did not found time until now to test your macro (for which a big thank you very much !).

I followed your instructions but I don't seem to get it to work.
I copied the macro to my ThisOutlookSession, restarted Outlook and enabled macro's but as from there it is unclear how to get it to work.

I understood that it would run whenever a message or task is flagged but I tried every flag type and it does not take all day events into account. I also tried to run the macro from the developer tab but same result, the macro can be run but nothing happens.

I did notice in the macro that it is based on a US region whil I'm in Europe, for example in the line Debug.Print Format(itm.Start, "m/d/yyyy") which I changed to Debug.Print Format(itm.Start, "d/m/yyyy").
Can this have an impact and would the above change in the code be correct ?

Can you provide me some more info on how to a apply this macro to the flags ?

Thank you in advance !

2
-2
Reply
Diane Poremsky
Author
Reply to  Phil
April 22, 2017 5:53 am

it won't run from the developer ribbon as written - so it wont appear to do anything when you try. The date format could definitely cause problems - you should use the one that matches the date format in windows. it will skip all day events that are not marked busy. That could be removed from the holiday sub: [BusyStatus] <> '0' AND - but hen it will skip every stupid little 'holiday' on your calendar, not just 'bank holidays'. it also won't use recurring events, because you'd need to get the date of each occurrence and that is too complicated for this.

1
-1
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 36

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Hide or Delete Outlook's Default Folders
  • How to Remove the Primary Account from Outlook
  • This operation has been cancelled due to restrictions
  • Removing Suggested Accounts in New Outlook
  • Reset the New Outlook Profile
  • iCloud error: Outlook isn't configured to have a default profile
  • Adjusting Outlook's Zoom Setting in Email
  • Online Services in Outlook: Gmail, Yahoo, iCloud, AOL, GoDaddy
  • Add Holidays to Outlook's Calendar
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment