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.
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.
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.
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", "firstname.lastname@example.org", "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 = "email@example.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,
|State||Enable, disable, or schedule the automatic reply. rdoOofDisabled = 0 rdoOofEnabled = 1 rdoOofScheduled = 2|
|ExternalAudience||Use rdoOofAudienceAll (value: 2) to send replies to all senders rdoOofAudienceKnown (value: 1) to send only to known senders rdoOofAudienceNone (value: 0) disables external replies.|
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:
- Right click on Project1 and choose Insert > Module
- 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.
- Go to Tools, References menu.
- Locate the Redemption object library in the list and add a checkmark to it.
More information as well as screenshots are at How to use the VBA Editor