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

Automatically block off time before and after meetings

Slipstick Systems

› Developer › Code Samples › Automatically block off time before and after meetings

Last reviewed on March 6, 2020     54 Comments

Applies to: Outlook (classic), Outlook 2010

I use these macros not for travel time, but to add prep and follow up time to meetings (and also in case we need a little more time to finish up) but they serve the same purpose: to block off time on the calendar so no one can invite you to a meeting too close to another meeting.

The first macro is automatic. It watches the calendar folder and when a new meeting is added, it creates busy appointments before and after the meeting to block the time off for meeting prep or travel time. This macro works only with meetings, not appointments.

If you prefer to add the time manually, the second macro on the page blocks off time before and after the selected appointment or meeting.

These macros use a set time for the added appointments, in this case 30 minutes, but you could just as easily use an input box to enter the time specific to a meeting or a userform to select from a list of times.

September 13 2018: Edited macro so it will create travel time appointments for both meetings you create and those you are invited to. Note that it will create the events when the meeting invitation arrives and is added to the calendar as Tentative. It will not remove the events if you decline the meeting.

' Add to ThisOutlookSession
Option Explicit
Private WithEvents CalendarItems As Items
Dim myCalendar As Outlook.Folder

Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
   
  Set myCalendar = objNS.GetDefaultFolder(olFolderCalendar)
  Set CalendarItems = myCalendar.Items

  Set objNS = Nothing
End Sub

Private Sub CalendarItems_ItemAdd(ByVal Item As Object)
Dim TimeSpan As Long

'how much time do you want to block (in minutes)
 TimeSpan = 30

'If Item.MeetingStatus = olMeeting Then
If Item.MeetingStatus = olMeeting Or Item.MeetingStatus = olMeetingReceived Then
    On Error Resume Next
  
Dim oAppt As AppointmentItem
Set oAppt = Application.CreateItem(olAppointmentItem)

With oAppt
    .Subject = "Meeting Prep Time " & Item.Subject    '30 minutes before
    .StartUTC = Item.StartUTC - TimeSpan / 1440
    .Duration = TimeSpan
    .BusyStatus = olBusy
    .ReminderSet = False
    .Save
End With

Set oAppt = Application.CreateItem(olAppointmentItem)
With oAppt
    .Subject = "Meeting Review Time " & Item.Subject
    .Start = Item.End
' use number for duration if you are using a different length here
    .Duration = TimeSpan
    .BusyStatus = olBusy
    .ReminderSet = False
    .Save
End With
End If
End Sub

Manually add travel time

Add this macro the a new module and create a button for it on the Quick Access Toolbar. To use, select an appointment and click the button.

Sub BlockOffTime()
    Dim objApp As Outlook.Application
    Set objApp = Application
   ' On Error Resume Next
  
Dim oAppt As AppointmentItem
Dim cAppt As AppointmentItem
  
Set cAppt = objApp.ActiveExplorer.Selection.Item(1)
Set oAppt = Application.CreateItem(olAppointmentItem)
'      MsgBox cAppt.StartUTC
With oAppt
    .Subject = "Meeting Prep Time"
    '30 minutes before
    .StartUTC = cAppt.StartUTC - 0.020833
    .Duration = 30
    .BusyStatus = olBusy
    .ReminderSet = False
    .Save
End With

Set oAppt = Application.CreateItem(olAppointmentItem)
With oAppt
    .Subject = "Meeting Review Time"
    .Start = cAppt.End
    .Duration = 30
    .BusyStatus = olBusy
    .ReminderSet = False
    .Save
End With

Set cAppt = Nothing
  
End Sub

Remove Past 'Time Block' Appointments

While it is fairly easy to use Instant Search or a list view to remove these meeting from your calendar, a simple macro can remove all previous meetings added to block off time.

Sub DeletePasteBlockTime()
 
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objVariant As Variant
    Dim lngMovedItems As Long
    Dim intCount As Integer
     
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderCalendar)
      
    For intCount = objSourceFolder.Items.Count To 1 Step -1
        Set objVariant = objSourceFolder.Items.Item(intCount)
        DoEvents
        If objVariant.Subject = "Meeting Prep Time" Or objVariant.Subject = "Meeting Review Time" Then
            If objVariant.Start < Now Then
              objVariant.Delete
               
              'count the # of items moved
               lngMovedItems = lngMovedItems + 1
 
            End If
        End If
    Next
     
    ' Display the number of items that were moved.
    MsgBox "Moved " & lngMovedItems & " messages(s)."
Set objDestFolder = 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 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. 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.

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

To use 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.)

Application_Startup macros run when Outlook starts. If you are using an Application_Startup macro you can test the macro without restarting Outlook by clicking in the first line of the Application_Startup macro then clicking the Run button on the toolbar or pressing F8.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor.

Automatically block off time before and after meetings was last modified: March 6th, 2020 by Diane Poremsky

Related Posts:

  • This macro copies a meeting request to an appointment. Why would you w
    Copy meeting details to an Outlook appointment
  • Accept or decline a meeting request then forward or copy it
  • Keep Canceled Meetings on Outlook's Calendar
  • Copy Selected Occurrence to an Appointment

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
54 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Jan
October 4, 2023 5:08 am

Hi Diane,
I get a run-time error and "Array index out of bounds"

0
0
Reply
Han
September 26, 2023 5:40 am

Hi Diane - thank you so much for this, it's incredibly useful and I appreciate you sharing the script. I have a quick query if you have time to consider it.

I'm using the first/auto version, and I find that when I receive a meeting I'm getting duplicate time blocks - so the time blocks go in when the invite is first received (and the meeting is in my diary as tentative), but then when I respond/accept the meeting, I get another two time blocks added. So I end up with four in total (two before and two after).

Am I doing something incorrect with the script?

Thanks in advance for your help.

0
0
Reply
Diane Poremsky
Author
Reply to  Han
September 26, 2023 3:52 pm

I'll test it (and update) - but I'm guessing it is this line - that is causing it to do it both when it arrives and when you reply. Or when it syncs back after accepting it. The best thing might be to check the status and only create if accepted.
If Item.MeetingStatus = olMeeting Or Item.MeetingStatus = olMeetingReceived Then

0
0
Reply
Han
Reply to  Diane Poremsky
October 2, 2023 6:32 am

Thanks you for your response Diane. Does this mean changing the Item.MeetingStatus = olMeetingReceived to Item.MeetingResponse = olMeetingAccepted?

0
0
Reply
Diane Poremsky
Author
Reply to  Han
October 2, 2023 10:33 am

I haven't had a chance to test it yet, but either that or check to see if accepted, then create the appointments.

0
0
Reply
Remco
August 14, 2023 7:48 am

My company don't allow to change the Marco security level, is there another option, like power automat, to achive this?

0
0
Reply
Diane Poremsky
Author
Reply to  Remco
August 14, 2023 10:10 am

Power automate might do it - I will look into it.

0
0
Reply
Amanda
April 26, 2023 8:13 am

I want to create an appointment (manually) that is for the first available 30-min slot starting 5 days before an appointment - is this possible? I've spent about an hour googling your site and also actual google :) and I've not come up with anything I can use. I'm good at modifying existing code but I can't write my own, so if someone could point me to something similar in VBA that would also help!

0
0
Reply
Kamil Dursun
January 31, 2023 6:07 am

Thank you, this is much better than "shorten meeting" option in Outlook.
In real life, you need buffer times both before and after meetings. It can be due to preparation, travel, etc.

0
0
Reply
Duane
December 28, 2022 11:34 am

Good morning,

Diane, can you send the most updated code for Automatically block off time before and after meetings
Duane

0
0
Reply
Diane Poremsky
Author
Reply to  Duane
December 28, 2022 11:37 am

This is only version I have. Is it not working for you?

0
0
Reply
Marco Mueller
December 10, 2020 3:28 am

Hello Diane,

absolutely helpful script! It's my first touch to VBA scripts but I love it from the beginning. :-)
I splitted the TimeSpan to TimeSpanBefore and TimeSpanAfter because I want to have different slots here. Works nice. The calendar does not look nie because my time span is just 5 and 10 minutes so all looks scrambled. But this is how Outlook displays eveything and has nothing to do with your script for sure.

The only thing which does not work is the cleanup of old entries. I made a meeting in the past and it was created with surrounding buffer. But starting the cleanup results in "moved 0 message(s)" and I don't see why. Is there anything special I have to take care for?

Regards
Marco

0
0
Reply
Khaled
August 19, 2020 3:21 am

Hi Diane, thank you so much.

My calendar now fully looks blue and it's hard to read what are actual meetings vs what is review/ prep time.

Is it possible to add color coding/ categorisation into this which makes it easier to glance meetings/ appointments?

Thanks

0
0
Reply
Diane Poremsky
Reply to  Khaled
August 19, 2020 4:56 pm

You can add .categories = "category name" to add a category to the appointments.

With oAppt
&nbsp;&nbsp;.Subject = "Meeting Prep Time"
  .categories = "category name"

0
0
Reply
Khaled
Reply to  Diane Poremsky
August 20, 2020 1:15 am

Thank you.

With oAppt
 .Subject = "Meeting Prep Time" '30 minutes before
 .StartUTC = Item.StartUTC - TimeSpan / 1440
 .Duration = TimeSpan
 .BusyStatus = olBusy
 .ReminderSet = False
 .Categories = "Gap"
 .Save
End With

Set oAppt = Application.CreateItem(olAppointmentItem)
With oAppt
 .Subject = "Meeting Review Time"
 .Start = Item.End
' use number for duration if you are using a different length here
 .Duration = TimeSpan
 .BusyStatus = olBusy
 .ReminderSet = False
 .Categories = "Gap"
 .Save

0
0
Reply

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

Latest EMO: Vol. 30 Issue 31

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
  • Jetpack plugin with Stats module needs to be enabled.
  • 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
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
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

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

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

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