<

Automating Out of Office in Outlook

Published on
45,104 Points
33,604 Views
15 Endorsements
Last Modified:
Awarded
Community Pick
Outlook’s “Out of Office” (OOO) feature is a wonderful tool if your mailbox is hosted on Exchange.  When it’s turned on, your Exchange server sends a reply to anyone who emails you, letting them know that you are out of the office.    

There’s the rub, though.  It only works if you remember to turn it on before exiting Outlook and leaving your office.  I can’t begin to count the number of times that I’ve been on my way out of town only to remember that I forgot to turn on OOO.  Fortunately I have a mobile device that allows me to turn it on remotely.  There are other ways to turn OOO on remotely (e.g. Outlook Web Access, a notebook and a VPN connection), but wouldn’t it be great if Outlook included a feature that turned it on automatically so you wouldn’t have to remember?  

One of the reasons that I’m an Outlook fan is its built-in support for scripting.  Scripting allows me to add a huge amount of functionality that Outlook doesn’t have out of the box.  And while I can’t add every feature I’d like Outlook to have, scripting allows me to add most of them.  This is one.  With a very simple bit of scripting I can automatically turn on OOO every time I close Outlook and turn it off again each time I launch Outlook.  

This works well for me because Outlook is always open when I’m in the office.  The only time it’s closed is when I leave the office.  I think of OOO less as an indicator of whether I’m physically in the office and more as a means of letting anyone who emails me know whether I’m available to respond to their message.  I realize that not everyone views it this way and that some folks won’t want to activate OOO each time they close Outlook.  This article is intended for those of you who do want OOO to kick in each time you close Outlook.

As I noted above, the code for this is very simple.  It works by monitoring the event that fires as Outlook begins its shutdown process.  By trapping that event, we can run the code that turns on the OOO feature.  Similarly, by monitoring the event that’s triggered each time Outlook launches we can run code that turns off the OOO notification.  Here’s the code for doing this.

Outlook 2007/2010

Follow these instructions to add the code to Outlook 2007/2010.

  1.  Start Outlook.
  2.  Click Tools > Macro > Visual Basic Editor.
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on 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.  Edit the code as needed.  I included comment lines wherever something needs to or can change.
  6.  Click the diskette icon on the toolbar to save the changes.
  7.  Close the VB Editor.
  8.  Click Tools > Trust Center.
  9.  Click Macro Security.
10.  Set Macro Security to "Warnings for all macros".
11.  Click OK.
12.  Close Outlook.
13.  Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Private Sub Application_Quit()
    OutOfOffice True
End Sub

Private Sub Application_Startup()
    'Remove this subroutine if you do not want to turn OOF off automatically.'
    OutOfOffice False
End Sub

Sub OutOfOffice(bolState As Boolean)
    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
    Dim olkIS As Outlook.Store, olkPA As Outlook.PropertyAccessor
    For Each olkIS In Session.Stores
        If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set olkPA = olkIS.PropertyAccessor
            olkPA.SetProperty PR_OOF_STATE, bolState
        End If
    Next
    Set olkIS = Nothing
    Set olkPA = Nothing
End Sub

Open in new window


Note: I have not tested the code with Outlook 2010.

Outlook 2003 and Earlier

Follow these instructions to add the code to Outlook 2003 and earlier.

  1.  Start Outlook
  2.  Click Tools > Macro > Visual Basic Editor
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
  5.  Outlook's VB Editor window
  6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
  7.  Click the diskette icon on the toolbar to save the changes
  8.  Close the VB Editor
  9.  Click Tools > Macro > Security
10.  Set the Security Level to Medium
11.  Close Outlook
12.  Start Outlook
13.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Private Sub Application_Quit()
    OutOfOffice True
End Sub

Private Sub Application_Startup()
    'Remove this subroutine if you do not want to turn OOF off automatically.'
    OutOfOffice False
End Sub

Sub OutOfOffice(bolState As Boolean)
    Dim mapSession As Object
    Set mapSession = CreateObject("MAPI.Session")
    With mapSession
        .Logon , , False, False, 0
        .OutOfOffice = bolState
        .Logoff
    End With
    Set mapSession = Nothing
End Sub

Open in new window

Note: CDO (Collaboration Data Objects) must be installed on the computer.  If you discover that CDO is not installed, then you can download it from this Microsoft page.
With this code in place, OOO will activate each time you close Outlook and will deactivate each time you launch Outlook.  Keep in mind that this solution will ONLY work if your mail is hosted on an Exchange server.  It will not work if your mailbox is hosted on a POP server.  I should also point out that the code only works from the full version of Outlook.  Outlook Web Access does not support scripts.

Enhancements

The code, as is, does not prompt for a message.  It simply turns OOO on or off.  You can use a generic message such as “I’m out of the office right now.  I’ll respond to your email when I return.”  If you want to be prompted for a message, then you can add that feature.
You may not want OOO to activate every time you close Outlook.  Perhaps you only want it turn on if you close Outlook after a certain time of the day.  For example, if it’s after 3:00 PM turn it on otherwise do nothing.  You can do that by adding an IF … THEN statement before the FOR … NEXT loop.
15
Comment
Author:David Lee
  • 7
  • 7
  • 3
  • +5
24 Comments
 
LVL 38

Expert Comment

by:younghv
BDF -
I really like it when someone takes the time to write an Article so well that I can understand it on the first read-through.
Excellent work and a big "Yes" vote above.

Thank you.
0
 
LVL 76

Author Comment

by:David Lee
Thanks, younghv!  I'm glad you found the article useful.  I took a peek at your bio and see that you're a retired CW4.  I'm a former CW2 (Army).  Small world.
0
 
LVL 5

Expert Comment

by:SavindraSingh
Thanks BDF,

I was thinking on the same lines to build an addon for MS Outlook that will allow the users to automatically change OOO status. Your artical has proved very useful to me.

But my requirements are a bit extensive to what is covered in above VBA code. I am trying to syncronise the OOO status based on the OOO events marked on Outlook calander.

As you are aware that while creating a new event on Outlook calander you can select the option to show the time as FREE/BUSY/TENTATIVE/OUT OF OFFICE. That is the exact place from where I want the code should decide whether to set the OOO status on or off.

I am trying to extend your code to achive my requirements. Meanwhile please let me know if you can provide some guidelines/help to achive this.

Thanks and regards,
Savindra
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 5

Expert Comment

by:SavindraSingh
While working on this task I was trying to figure out the event at which the OOO should get enabled and disabled.

I found below code to trigger this task.

Can we set the message for OOO through your code?
Private Sub Application_Reminder(ByVal Item As Object)

If Item.BusyStatus = olOutOfOffice Then
    OutOfOffice True
End If

End Sub

Open in new window

0
 
LVL 76

Author Comment

by:David Lee
Hi, SavindraSingh.

Glad the article was helpful.  Yes, I can help with this.  However, rather than handling this here in the comments of the article, could you open a question?
0
 
LVL 5

Expert Comment

by:SavindraSingh
Hello BDF,

I have posted the question on below link:

http://www.experts-exchange.com/Microsoft/Applications/Q_26652298.html

Thanks in advance.
0
 

Expert Comment

by:Amanda Camarata
Thanks for posting this! I know this is a little older, but I had a question --

Is it possible to automate an OOO reply when your calendar indicates you are out of the office? I don't see a way to make a rule for this.

-Amanda
0
 
LVL 76

Author Comment

by:David Lee
Hi, Amanda.

I need to be clear on what you're asking before I can give an answer.  Are you asking if you can have Outlook automatically activate OOO whenever an appointment begins that has "Show As" set to "Out of Office", or are you asking if it's possible to emulate OOO when a message arrives while in an appointment that has "Show As" set to "Out of Office"?
0
 

Expert Comment

by:Diwi1
Hi BDF,

this script would be very useful for me as well, but it is obviously not supported with Outlook 2010 cause CDO 1.2.1 will not work with Outlook 2010: https://support.microsoft.com/kb/2028411/en-us.
Is there a solution for Outlook 2010 ?

Regs
Gary
0
 
LVL 76

Author Comment

by:David Lee
Hi, Gary.

The code in the Outlook 2007/2010 portion of the solution does not use or depend on CDO.  It's a pure Outlook solution and it works fine in any version of Outlook from 2007 on.  It's only the 2003 portion of the solution that requires/uses CDO.
0
 

Expert Comment

by:Diwi1
Hi BDF,

thanks for the post, then I´m doing something wrong. I followed the instructions from 1-13. When Outlook is closed and I send a test e-Mail no oof message comes back.
Starting Outlook will show the macro warning and obviously disables oof cause it´s not active anymore.
Am i missing something ?

Regs Gary
0
 
LVL 76

Author Comment

by:David Lee
Hi, Gary.

Time for a little troubleshooting.  Please add the code below to the code you already have.

Private Sub ActivateOOF()
    OutOfOffice True
End Sub

Private Sub DeactivateOOF()
    OutOfOffice False
End Sub

Open in new window


Once you've done that, please run the ActivateOOF macro, then check to see if OOF is turned on by clicking File -> Automatic Replies.  If it is turned on, then send yourself a test message from another mailbox.  Do you get an OOF response?  If you don't, then you'll need to talk to your mail administrator.  If after running ActivateOOF you find that OOF is not turned on, then something is wrong and we'll need to investigate what.
0
 

Expert Comment

by:Diwi1
Hi BDF,

thank you for the post. I know now exactly waht the problem is: when automatically activating oof through the makro, the checkbox "Reply to persons outside the company" isn´t checked automatically and thus no one external gets the message, I tried many times to check this option, but when deactivating OOF with the macro this option is always disabled. When I do it manually it works.
0
 

Expert Comment

by:Diwi1
Hi BDF,

are there any news regarding this case ?
0
 

Expert Comment

by:Amanda Camarata
I don't know why I never saw that there were replies to this ---

To clarify, I am asking if you 'can have Outlook automatically activate OOO whenever an appointment begins that has "Show As" set to "Out of Office"'.

Just as I would set an Out of Office reply when I'm on vacation -- I want the OOO to respond to messages sent to me when I am in appointments where I have marked my calendar "Out of Office". They are so scattered that I feel like it would be a great time saver and tool for my partners.

I hope that helps.
0
 

Expert Comment

by:Diwi1
Hi Amanda,

I don´t know what you mean exactly. In my conversation with BDF we talked about an Outlook Skript that activates OOO when closing Outlook. But there is this one checkbox  "Reply to persons outside the company", that isn´t checked automatically and therefore no OOO-message is sent to external recepients.

Best regards
Gerald
0
 

Expert Comment

by:Amanda Camarata
Are you saying that what I'm asking is not possible or I still haven't been clear on what I'm trying to figure out?

Sorry for the confusion.

Amanda
0
 

Expert Comment

by:Diwi1
Hi Amanda,

I don´t how to set an "appoitment" to "Show As2 "Out of office" and that is not the topic. What the cutsomer needs is set "Out of Office" notice generally when Outlook is closed.

Regs
Gerald
0
 
LVL 76

Author Comment

by:David Lee
Gerald,

What version of Outlook are you using?
0
 
LVL 76

Author Comment

by:David Lee
Hi, Amanda.

Yes, what you've described is possible.  There are actually two ways to do this.  One, turn OOO on when an appointment begins and turn it off again when an appointment ends.  Second, each time a new message arrives check to see if you're in an appointment.  If you are, then send a pseudo-OOO response (I say pseudo because it wouldn't be an actual OOO response, it would be like an OOO response).  The main difference between the two is that OOO will only respond to each sender once, whereas the second approach will respond to every message they send.  Beyond that, there are limitations on automating OOO without resorting to third-party tools.  That makes the second approach slightly more viable than the first approach.
0
 

Expert Comment

by:Diwi1
Hi BDF,

I´m using Outlook 2010.
0
 

Expert Comment

by:JHecht23
Hello there,
I saw the question asked regarding turning on the Out of Office AND somehow checking the "Auto-reply to people outside my organization" checkbox (or the code equivalent of checking the box!)

I didn't see a posted answer, and this would solve my problem in a major way! Some of our team members have varying or different hours/shifts, and I want an auto-reply or Out of Office message sent so the sender knows that their recipient is not in.

Any advice is GREATLY appreciated. Thank you!
-Jeremy
0
 

Expert Comment

by:Julie Flind
It looks like this website might be able to make this easier http://www.thebusyapp.com
0
 

Expert Comment

by:Caroline Rudland
Thank you for this code - it's very useful :-)

I have a couple of possible extensions please?

I would like to be able to change the text of the OOO reply when it is set - is this possible? Preferably slightly different inside & outside my organisation!

Also, I would like to be able to set it so it replies to "My Contacts" "Outside My Organisation" - is that also possible?

Many thanks :-)
0

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Join & Write a Comment

Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Discover the basics of using Outlook 2016 from office 365.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month