The VBA script I built allows you to automate out-of-office (OoO) messages. Depending on the day of the week and upcoming appointments, the program automatically creates the corresponding OoO message.

Ben Norcutt

Ben Norcutt is a Microsoft Certified IT Professional (MCITP) with 13 years experience inIT administration in educational establishments.

Note that I've only tested the code with Outlook on Windows 10. Once you understand how my script works, you can adapt it easily to your environment.

I run the script in two ways:

  1. I have a button on my toolbar that calls the macro, checks the current day for any out-of-office appointments, and then sets my OoO status accordingly.
  2. When Outlook exits, it checks the current day. If it's Friday, it checks for any OoO appointments on Monday and sets the OoO status accordingly. If it’s not Friday, it just checks the next day.

Before using my script, I recommend going into your Outlook out-of-office settings (File > Info > Automatic Replies) and adding a generic OoO message, something along the lines of "I'm currently out of the office and will respond upon my return."

Outlook out of office settings

Outlook out of office settings

The current code pops up message boxes to inform you what the script is doing, but you could comment those out to make the script completely silent.

To get started using the code:

  1. Start Outlook.
  2. Press Alt + F11 to open the Visual Basic Editor.
  3. If not already expanded, expand Microsoft Office Outlook Objects.
  4. If not already expanded, expand Modules.
  5. Select an existing module (such as Module1) by double-clicking it, or create a new module by right-clicking Modules and selecting Insert > Module.
  6. Copy the code from the code snippet box and paste it into the right-hand pane of Outlook's VB Editor window.
  7. Click the diskette icon on the toolbar to save the changes.
  8. Close the VB Editor.

Below is the complete VBA code. I added comments to help you understand what the script is doing:

We need to put the code that runs when Outlook exits in a slightly different place.

  1. Press Alt + F11 to open the Visual Basic Editor.
  2. If not already expanded, expand Microsoft Office Outlook Objects.
  3. If not already expanded, expand ThisOutlookSession.
  4. Copy the code from the code snippet box and paste it into the right-hand pane of Outlook's VB Editor window.
  5. Click the diskette icon on the toolbar to save the changes.
  6. Close the VB Editor.
Location of the exit code

Location of the exit code

And this is the exit code:

That's the end of all the code required. Each subroutine has comments explaining what it does.

My ribbon button looks like this:

Out of office ribbon button

Out of office ribbon button

Clicking it will run the code. In this example, it returns "do nothing" because I have OoO already turned on and there is an OoO appointment today. Following the logic of the what-to-do subroutine, this triggers case 3.

"Do nothing" warning

When I exit Outlook, it asks me if I would like to run Auto Out of Office.

Pop up window when exiting Outlook

Pop up window when exiting Outlook

It's Friday:

Friday pop up message

Friday pop up message

Looking ahead to Monday, we trigger case 3 again:

Triggering case 3 again

Triggering case 3 again

Starting up Outlook runs the little piece of code we have in Sub Application_Startup(). Due to the default security settings, it prompts the user to enable macros. This is just so I can now hit my ribbon button or shut down Outlook, and it won’t prompt me to enable macros anymore.

Prompt to enable macros

Prompt to enable macros

Win the monthly 4sysops member prize for IT pros

1+

Users who have LIKED this post:

  • avatar
Share

Related Posts

2 Comments
  1. Matt D 1 year ago

    Great tip!  Very useful!!

    1+

    Users who have LIKED this comment:

    • avatar
  2. Ritesh 2 months ago

    Hi,

    I was actually looking for exactly the same solution.

    This is not working fine in outlook 2016.

    Could you please help if I have to do any other settings?

    I tried creating an Out of office Appointment / Meeting and then RAN the code. It shows "Do Nothing". And If I run it again, it shows: "About to Disable out of office". But never could I see "About to enable out of office".

    Am I missing something here?

    Thanks in advance.

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2019

Log in with your credentials

or    

Forgot your details?

Create Account