Automating Outlook Out of Office

15 pts.
Microsoft Outlook
Outlook Out of Office
is it possible to automate the out of office function as i job share and am only in the office 3 days a week, so emails that come in from anyone automatically get the out of office message without me having to set the out of office each week. (In case I forget to set it) Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

I found some Visual Basic Application code that you can use to automate when you close outlook to display an out of message reply.

Here is the code:

Private Sub Application_Quit()
Dim objMAPISession As Object
Set objReminders = Nothing
If MsgBox(“Would you like to turn the Out of Office Assistant on?”, vbYesNo, “Activate Out of Office Assistant”) = vbYes Then
Set objMAPISession = CreateObject(“MAPI.Session”)
objMAPISession.Logon , , True, False
objMAPISession.OutOfOffice = True
End If
Set objMAPISession = Nothing
End Sub

Here are the instructions to get this going:

1. Open up Outlook.
2. Click Tools->Macros->Visual Basic Editor.
3. If not already expanded, expand Microsoft Office Outlook Objects and select ThisOutlookSession.
4. Copy the code and paste it into the right-hand pane of the VB editor.
5. Click the diskette icon on the toolbar to save the code.
6. Close the VB editor.
7. Click Tools->Macros->Security.
8. Change the security level to Medium.
9. Click Ok.
10. Close Outlook.
11. Start Outlook.
12. You’ll receive a dialog-box telling you that ThisOutlookSession contains macros and asking if you want to enable them. Click Enable Macros.
13. Try closing Outlook. When you do a dialog-box should appear asking if you want to turn the Out of Office Assistant on. If you click Yes it will be turned on.

Clicking No will leave it off.

Discuss This Question: 9  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    what mail software (client and server) are you using ?
    85,470 pointsBadges:
  • Technochic
    I expect you are using outlook. What version and service pack level please?
    57,010 pointsBadges:
  • UNSW
    Hi yeah Microsoft Outlook 2007 - I believe it's SP1. Cheers
    15 pointsBadges:
  • Technochic
    Karl, what a great solution, thanks for posting that!
    57,010 pointsBadges:
  • Birdlog
    simple but useful nice one chap!
    10 pointsBadges:
  • Jbrickey
    This doesn't appear to be working in Outlook 2007. I receive a Run-time error on Set objMAPISession = CreateObject("MAPI.Session"). Any suggestions? Thanks!
    10 pointsBadges:
  • Pappu
    Hi All, For the above code to work in Outlook 2007 try installing the package at This should solve the problem for run time errors during the code execution. Thanks, Pappu.
    10 pointsBadges:
  • mwhelp
    What should the code be when you have Application_Start()? Need something to run when they turn outlook on and when they logoff.
    10 pointsBadges:
  • trishkaken

    Hi - I realize this is an old thread but I can't find anything recent and I'm hoping someone can help me. I'd like to deploy something like this with a mailbox I monitor. We have Outlook 365 and Windows 10. When I add the code above, I get a Run-time error '429': ActiveX component can't create object. When I click the Debug button it points to this line of the code being the issue:

    Set objMAPISession = CreateObject(“MAPI.Session”)

    In searching for that error online, I see the code uses CDO 1.2.1 which is only supported with Outlook 2007.

    Would anyone have code to do this same function with Outlook 365? I've spent hours looking online but cannot find a solution.

    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: