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

Enable Automatic Replies (OOF) using a macro

Slipstick Systems

› Developer › Enable Automatic Replies (OOF) using a macro

Last reviewed on September 27, 2021     21 Comments

Applies to: Outlook (classic)

A user asked me for a macro to turn off the Out-Of-Office setting when he gets back in the office, although I'm not sure why anyone would want to use a macro for this as Outlook has a feature that lets you schedule Automatic Replies, and it can turn Automatic Replies on and off automatically.

schedule automatic replies

You need to set it up each time (you can't say 'every day from 5 pm until 8 am tomorrow'), but you can schedule it ahead of time. Every morning when you come in, you can turn it off and reset it to come back on after 5 pm.

Plus, Outlook is really good about popping up a banner reminding you that Automatic replies are on.

Outlook reminds you that out of office is on

What you really need is a macro to turn automatic replies on and set the times for you.

You can find a lot of older macros on the internet that can turn Out-of-Office off and on but they only work in Outlook 2007 and older as they use CDO. As of Outlook 2010, Outlook does not use CDO.

If you want to use a macro to enable automatic replies in newer versions of Outlook, you need to use Redemption's RDOOutOfOfficeAssistant object to update Automatic Replies using a macro.

A macro makes it a lot easier to set up automatic replies if you have more than one Exchange account and want to set the same out of office message on each account.

 

Update Automatic Replies

This macro sample asks for the start and end dates and uses a predefined start and end times. (I like to enable automatic replies early, so people who email right before I leave the office know I'm out.) You can enter the date in any valid format, such as "1/17" (Outlook will add the year). The macro will enable and configure automatic replies in all business Exchange accounts in your profile. As written, it skips Outlook.com accounts because they do not support automatic replies to internal addresses.

automatic replies are enabled

To use this macro, add it to the Quick Access toolbar or ribbon or use a reminder to trigger it. You'll also need to install Redemption Developer version.

Sub setOOF()
Dim sStart As Date
Dim sEnd As Date
Set rdo = CreateObject("Redemption.RDOSession")

Session.Logon
rdo.MAPIOBJECT = Application.Session.MAPIOBJECT
rdo.Credentials.Add "outlook.office365.com", "me@domain.com", "password"

sStart = InputBox("Start date for OOF.", "OOF dates", Date)
sEnd = InputBox("End date for OOF.", "OOF dates", Date + 3)

For Each Store In rdo.Stores
If (Store.StoreKind = skPrimaryExchangeMailbox) Then
   Debug.Print Store.Name
' Skip Outlook.com accounts as they don't have internal and external OOF options.
  If Store.Name = "me@outlook.com" Then GoTo NextStore

Set OOFAssistant = Store.OutOfOfficeAssistant
OOFAssistant.OutOfOffice = True

OOFAssistant.BeginUpdate
OOFAssistant.StartTime = sStart + #3:00:00 PM#
OOFAssistant.EndTime = sEnd + #10:00:00 AM#
OOFAssistant.State = 2 'rdoOofScheduled
OOFAssistant.ExternalAudience = 2 '2 = All; 1 = Contacts only
OOFAssistant.OutOfOfficeTextInternal = "<html><body>I am out of the office currently and will return on " & Format(OOFAssistant.EndTime, "dddd, MMMM dd, yyyy at hh:mm AM/PM") & "." & _
  "</body></html>"
OOFAssistant.OutOfOfficeTextExternal = "<html><body>I am out of the office currently and will return on " & Format(OOFAssistant.EndTime, "dddd, MMMM dd, yyyy at hh:mm AM/PM") & "." & _
  "</body></html>"
OOFAssistant.EndUpdate
End If
NextStore:
Next
End Sub

To use this macro to enable automatic replies every day before you leave the office, change these lines.

sStart = InputBox("Start date for OOF.", "OOF dates", Date)
sEnd = InputBox("End date for OOF.", "OOF dates", Date + 1)

OOFAssistant.StartTime = sStart + #4:55:00 PM#
OOFAssistant.EndTime = sEnd + #8:45:00 AM#

The table below lists the possible values for two properties, State and ExternalAudience. For a complete explanation of all properties, see RDOOutOfOfficeAssistant object,

PropertyPossible Values
StateEnable, disable, or schedule the automatic reply. rdoOofDisabled = 0 rdoOofEnabled = 1 rdoOofScheduled = 2
ExternalAudienceUse rdoOofAudienceAll (value: 2) to send replies to all senders rdoOofAudienceKnown (value: 1) to send only to known senders rdoOofAudienceNone (value: 0) disables external replies.
 

Different OOF Weekdays and Weekends

This version of the macro checks the days of the week. If it's a weekday, the out of office is set to end the next morning. If it's Friday, the out of office ends in 3 days.Run it manually each day or use a reminder to trigger it.
Sub setOOFWeekdays()
Dim sStart As Date
Dim sEnd As Date
Set rdo = CreateObject("Redemption.RDOSession")

Session.Logon
rdo.MAPIOBJECT = Application.Session.MAPIOBJECT
rdo.Credentials.Add "outlook.office365.com", "alias@domain.com", "password"

sStart = Date

dayname = WeekdayName(Weekday(sStart))

Select Case dayname
Case Sunday, "Monday", "Tuesday", "Wednesday", "Thursday"
    sEnd = Date + 1
Case "Friday"
    sEnd = Date + 3
Case "Saturday"
    sEnd = Date + 2
End Select

For Each Store In rdo.Stores
If (Store.StoreKind = skPrimaryExchangeMailbox) Then
   Debug.Print Store.Name
' Skip Outlook.com accounts as they don't have internal and external OOF options.
  If Store.Name = "me@outlook.com" Then GoTo NextStore

Set OOFAssistant = Store.OutOfOfficeAssistant
OOFAssistant.OutOfOffice = True

OOFAssistant.BeginUpdate
OOFAssistant.StartTime = sStart + #4:00:00 PM#
OOFAssistant.EndTime = sEnd + #9:00:00 AM#
OOFAssistant.State = 2 'rdoOofScheduled
OOFAssistant.ExternalAudience = 2 '2 = All; 1 = Contacts only
OOFAssistant.OutOfOfficeTextInternal = "<html><body>I am out of the office currently and will return on " & Format(OOFAssistant.EndTime, "dddd, MMMM d, yyyy at h:mm AM/PM") & "." & _
  "</body></html>"
OOFAssistant.OutOfOfficeTextExternal = "<html><body>I am out of the office currently and will return on " & Format(OOFAssistant.EndTime, "dddd, MMMM d, yyyy at h:mm AM/PM") & "." & _
  "</body></html>"
OOFAssistant.EndUpdate
End If
NextStore:
Next
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.

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:

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

Set a reference to Redemption Object Libraries If you receive a "User-defined type not defined" error, you need to set a reference to another object library.

  1. Go to Tools, References menu.
  2. Locate the Redemption object library in the list and add a checkmark to it.
    reference redemption library

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

More Information

RDOOutOfOfficeAssistant object
Enable Automatic Replies (OOF) using a macro was last modified: September 27th, 2021 by Diane Poremsky

Related Posts:

  • Use Powershell to configure Automatic Replies
  • Use Automatic reply rules without sending an Out of Office message
  • Where is the Out of Office command?
  • Use PowerShell or VBA to get Outlook folder creation date

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

reyhan
March 22, 2025 3:17 am

thank you very much of information

0
0
Reply
Phil Reinemann
March 6, 2024 6:07 pm

I think it may be because when I go to that website from the error message, I cannot sign in there. That was the https://outlook.office365.com/EWS/Exchange.asmx" site.

0
0
Reply
Phil Reinemann
March 6, 2024 6:02 pm

I modified the upper-most above code so that it's only called when I exit Outlook on Monday and Wednesday after 6:19PM. (I'm out of office Tuesday and Thursday.)

Everything is okay until statement "OOFAssistant.StartTime = sStart + #6:29:00 PM#" is called I get ""EWS is not available: HTTP error 401 from https://outlook.office365.com/EWS/Exchange.asmx".

I am in an Office 365 corporate environment and have no outlook.com email to interfere with the code.

Any ideas? Might it be that FMA has to be accounted for in the code, even though, to have Outlook running MFA has already been completed? (I just opened web-mail and didn't have to do any authentication, but I don't know if that carries through to the setOOF code.

0
0
Reply
Phil Reinemann
February 9, 2024 5:27 pm

If you just want to turn on OOF when exiting Outlook, see Diane's macro for that here: Prompt to turn on "Out of Office" replies (slipstick.com)

That's what I needed, nothing as complex as the above.

Thank you once again, Diane.

0
0
Reply
Phil Reinemann
Reply to  Phil Reinemann
March 6, 2024 12:10 pm

Unfortunately, my reference to Diane's article above was for Office below 2010.

You must use the code here for Office/Outlook 2010 and above.

0
0
Reply
Felipe V
September 6, 2023 4:47 pm

Redemption, as far as I'm reading, is not part of Outlook & furthermore requires a license. Redemption Developer is for testing uses only, according to their page.
As of 2023, is there any better alternative?

0
0
Reply
Diane Poremsky
Author
Reply to  Felipe V
September 7, 2023 10:29 am

It only requires a license if you are redistributing it. You don't need a license for personal use. Use the Developer version - you should only see the nag screen once, the first time it is installed.

0
0
Reply
John
March 5, 2021 1:41 am

Hi Diane,

Thanks for sharing this information as this is exactly what I need. However this script will enable automatic replies Every Day at the specified time, including weekends.

Is it possible the script can be modified so that it does the following?

  1. Turns automatic replies on automatically at 4:45pm on weekdays only
  2. Turns automatic replies off automatically at 8:45am on weekdays only
  3. Automatic replies stays on when it's weekend(Saturday and Sunday) after 4:45pm on Friday and turns off at 8:45am on Monday
0
0
Reply
Diane Poremsky
Author
Reply to  John
March 5, 2021 10:35 am

That can be done with an If statement that checks the date and if Fri, do it for 3 days. I'll try to update it today. .

0
0
Reply
Diane Poremsky
Author
Reply to  John
March 8, 2021 1:36 am

I added an updated version that sets the end date based on the day of the week.

0
0
Reply
John
Reply to  Diane Poremsky
March 9, 2021 5:11 pm

Thanks Diane! Much appreciated!

0
0
Reply
John
Reply to  Diane Poremsky
July 22, 2021 10:53 pm

Hi Diane,

Sorry to circle back on this after 4 months as it look me a while to get the macro going in outlook.

I've just recently found out that on Thursdays and Fridays it'd set the end day to Sunday and it'd reflect in the OOO message.

Today(23rd July Friday), I clicked the macro and below is in the OOO message(I've removed the time from the script)

"Hello, I am currently unavailable and will return on Sunday, July 25, 2021."

I am in a different timezone(GMT + 10), so not sure if that's relevant?

As a test, I've tried to increment 3 to 4 for the case "Friday" but it still shows Sunday.

Case "Friday"
    sEnd = Date + 4

Would you be able to help?

0
0
Reply
Diane Poremsky
Author
Reply to  John
July 22, 2021 11:30 pm

time zone shouldn't matter.

Are you using the macro under "Different OOF Weekdays and Weekends" ?

Last edited 4 years ago by Diane Poremsky
0
0
Reply
John
Reply to  Diane Poremsky
July 28, 2021 8:11 pm

Hi Diane,

Yes I am using the macro under "Different OOF Weekdays and Weekends". It works fine on Monday, Tuesday, and Wednesdays.

But on Thursdays and Fridays, the end date is set to Sunday for some reason.

I have not tested the macro on Saturday and Sunday yet.

0
0
Reply
Diane Poremsky
Author
Reply to  John
July 29, 2021 12:59 am

I'll test it... since its Thursday, I should know soon if I screwed up the code. :)

0
0
Reply
Diane Poremsky
Author
Reply to  John
July 29, 2021 1:24 am

Thurs is getting me an end date of Friday - which is correct, per the select case.
It looks like I'm missing the quotes on Sunday - so it will error unless you fix that in your code.

Case Sunday, "Monday", "Tuesday", "Wednesday", "Thursday"
sEnd = Date + 1
Case "Friday"
sEnd = Date + 3
Case "Saturday"
sEnd = Date + 2
End Select

I tested it by changing sStart = Date to sStart = Date + 1 (then 2, 3 and 4)
if you do that, you need to change the select case to use sstart instead of date. And added debug.print so I didn't have to check the oof dialog every time. :)

sStart = Date + 3

dayname = WeekdayName(Weekday(sStart))
Debug.Print dayname

Select Case dayname
Case "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"
sEnd = sStart + 1
Case "Friday"
sEnd = sStart + 3
Case "Saturday"
sEnd = sStart + 2
End Select

Debug.Print sStart, sEnd

0
0
Reply
John
Reply to  Diane Poremsky
August 2, 2021 2:30 am

Thanks Diane! Let me test that out this Thurs/Friday

Edit: I added "" for Sunday as I thought that was the problem but it wasn't it. Could be my user error. Thanks for checking.

Last edited 4 years ago by John
0
0
Reply
John
Reply to  Diane Poremsky
August 2, 2021 3:02 am

I've just tested it by replacing the bits above with code from sStart = Date + 3 to the debug.Print sStart,sEnd line.

It sets the start time to Thursday correctly but still shows Sunday in the oof dialog.(See attached)

I don't know how the debug.print works as it didn't show anything when I click the macro in outlook.

oof.JPG
0
0
Reply
Victor Ivanidze
Reply to  John
September 26, 2022 8:23 am

Have a look at this: https://www.ivasoft.com/scheduledoofflow.shtml

0
0
Reply
Victor Ivanidze
Reply to  Diane Poremsky
December 20, 2021 4:43 am

There exists a ready to use tool named "ScheduledOOF flow for Office 365"

0
0
Reply
Erik
Reply to  Diane Poremsky
June 20, 2023 2:01 pm

I am several years behind but need a code that will turn on OOF and auto replies every OTHER friday. They've got us on a new rotating schedule and I cannot find any solutions.

0
0
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
  • How to Hide or Delete Outlook's Default Folders
  • Adjusting Outlook's Zoom Setting in Email
  • Reset the New Outlook Profile
  • This operation has been cancelled due to restrictions
  • Syncing Outlook with an Android smartphone
  • Add Holidays to Outlook's Calendar
  • Online Services in Outlook: Gmail, Yahoo, iCloud, AOL, GoDaddy
  • Removing Suggested Accounts in New Outlook
  • 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 © 2026 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