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

How to Process Mail After Business Hours

Slipstick Systems

› Outlook › Email › How to Process Mail After Business Hours

Last reviewed on May 23, 2019     10 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

I have a macro that defers sending messages that are composed during a specific time period, such as during the overnight hours. After several users asked how to send responses or forward messages if the new messages arrived during the overnight hours, it's time to add macros for incoming messages as well.

I would like to forward the emails between 23.00 and 6 in the morning.
How do I set a recurring auto response rule every day between 6PM to 1AM with a custom message?

Obviously, you could use a rule and turn it on every evening and turn it off in the morning. If you use Exchange Server, you could use Automatic Replies (out-of-office) and create a rule to forward messages. Automatic replies can be set to turn on and off at a specific time but would need to be reset each day.

There are a few ways to automate this for incoming mail that will work with any account type. The only caveat: Outlook may need to be running for these methods to work.

The choices: 1) A reminder triggers a macro that turns the rules on and off at the appointed time or 2) a run a rule script that checks the time. In some cases, an ItemAdd macro that checks the time might be better than a rule, but the script is similar for both.

If you need to filter the messages and only reply or forward specific messages, it's easier to use a rule. The script at Enable or Disable an Outlook Rule using Reminders works great if you need the rule running at different times on different dates as you can create tasks or appointments for each start or end time. If you have an Exchange mailbox or Outlook.com configured using Exchange and the rule is server-side, you can close Outlook after the reminder macro turns the rule on.

You can leave the rule running all the time and use a script check the time. Warning: the script needs to do all actions; you can't move messages using the rule and reply using the script.

The example below sends a reply if it's after 5:45 PM or before 6:45 AM. If you are working in whole hours, you can use Hour(Time) in the If statement, with afternoon hours in 24-hour time format. In this example, messages that arrive after 5PM or before 7AM are processed by the rule.
If Hour(Time) >= 17 Or Hour(Time) <= 7 ThenThis sample script replies to the sender using a template. To reply with the original message, use Set oRespond = Item.Reply To forward the message, use Set oRespond = Item.Forward

Public Sub AutoReplyOvernight(Item As Outlook.MailItem)
 If Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #5:45:00 PM# _
Or Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #6:45:00 AM# Then
'send the autoreply
Set oRespond = Application.CreateItemFromTemplate("C:\path\to\reply.oft")
With oRespond
 .Recipients.Add Item.SenderEmailAddress
.Body = "The office is closed. " &amp; vbcrlf &amp; item.body
.send
End with
End if
End Sub

Use an ItemAdd macro

An ItemAdd macro can process more messages per minute than a rule. This can be helpful to POP3 users who receive a large amount of email. Other advantages are that you don't need to create a rule to use it and it can watch any folder, while the disadvantages are that it can't be turned off and will run each time a new message arrived in the watched folder, all day long.

This macro goes in ThisOutlookSession

Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objItems As Outlook.Items

Private Sub Application_Startup()
Dim objWatchFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")
 
'Set the folder and items to watch:
Set objWatchFolder = objNS.GetDefaultFolder(olFolderInbox)
Set objItems = objWatchFolder.Items
 
Set objWatchFolder = Nothing
End Sub

Private Sub objItems_ItemAdd(ByVal Item As Object)
If Hour(Time) >= 17 Or Hour(Time) <= 7 Then
Set oRespond = item.forward
With oRespond
 .Recipients.Add Item.SenderEmailAddress
.Send
End with

End if
End Sub

 

How to Use Macros

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

To check your macro security in Outlook 2010 and above, 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.

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

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.

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.

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

More Information

How to use an ItemAdd Macro
Outlook's Rules and Alerts: Run a Script
Process messages received on a day of the week
How to Process Mail After Business Hours was last modified: May 23rd, 2019 by Diane Poremsky

Related Posts:

  • Forward email messages by date
  • Send a New Message when a Message Arrives
  • 'Have server reply' rule is not using 'reply-to' address
  • Send Out of Office Replies with Outlook.com, POP, or IMAP accounts

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

Victor Ivanidze
May 11, 2022 12:32 pm

There exists a ready-to-use solution: OffHours.

0
0
Reply
Sandeep Rawat
June 7, 2021 1:28 am

It gives an error at Set oRespond = Item.Forward, variable not defined.

0
0
Reply
Diane Poremsky
Author
Reply to  Sandeep Rawat
June 7, 2021 1:57 am

Either remove option explicit or add Dim oRespond before that line.

1
0
Reply
Sandeep Rawat
Reply to  Diane Poremsky
June 10, 2021 12:50 am

Thank Diane, it worked with the recommended steps.

However I have another concern, my automatic replies are forwarding blank mails as per macros used.

What I have done:
I have saved the template file (C:\path\to\reply.oft) with the content that I want to reply during off hours.

From the module macros, i have not included anything. and Just keeping the same line.

.Body = "The office is closed. " &amp; vbcrlf &amp; item.body

This Outlook session macros is same as you have mentioned.

Set oRespond = Item.Reply
With oRespond
 .Recipients.Add Item.SenderEmailAddress
 .Send
End With

How can I pull the mail template as a response?

0
0
Reply
Diane Poremsky
Author
Reply to  Sandeep Rawat
June 10, 2021 12:54 am

use
Set oRespond = Application.CreateItemFromTemplate("C:\path\to\reply.oft")

0
0
Reply
Sandeep Rawat
Reply to  Diane Poremsky
June 10, 2021 4:34 am

Yes, I have set it in the Module macros. It's still not working.

0
0
Reply
Diane Poremsky
Author
Reply to  Sandeep Rawat
June 10, 2021 10:39 am

Use this macro to run a run a script macro on the selected message - change "YourMacroName " to the name of your macro. Does it work?

Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub

0
0
Reply
Victor Ivanidze
June 14, 2020 4:42 am

There exists an add-in for Outlook named OffHours: https://www.ivasoft.com/offhoursaddin.shtml

0
0
Reply
Oliv
April 25, 2019 4:19 am

Microsoft FLOW is a new solution for Office 365, to automate treatments!

0
0
Reply
saravanan
January 22, 2017 2:10 am

I am Using windows 10, Excel 2013 and Outlook 2013

I am new to Macro. I need macro to perform below Task.

1) From Excel I want to open Outlook if Outlook is closed and move Point.2, If outlook is already open then move to Point.2

2) Search for a specific email in outlook in all folders and sub folders with criteria “A” and “B”

a) Latest dated received or sent email.

b) With specific Subject contains “Status of EB Proposals - Sam Lucas”.

3) Open the found latest mail as per above criteria do “Reply all”.

4) Copy excel sheet as reply message on outlook body and send

2
-2
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 Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • This operation has been cancelled due to restrictions
  • Adjusting Outlook's Zoom Setting in Email
  • How to Hide or Delete Outlook's Default Folders
  • Disable "Always ask before opening" Dialog
  • Removing Suggested Accounts in New Outlook
  • Remove a password from an Outlook *.pst File
  • Syncing Outlook with an Android smartphone
  • 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