Reoccurring Out-of-Office

Posted on 2014-03-24
Last Modified: 2014-05-03
Hello all,

This is in reference to article:

I am trying to set up Outlook to check what day of the week tomorrow would be and turn on out of office during 8am-5pm that day, if it was a specific day.

Example: Every Monday at the end of the day, Outlook would set the OOO for business hours on Tuesday - (This would be helpful for a part-timer that doesn't work on Tuesday's).

This employee's messages are vital to the business and would wouldn't want to risk them forgetting to turn it on for our customers.
Question by:Guy-in-Transition
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

by:Trenton Knew
ID: 39951847
Delegate another user to that employee's mailbox so someone can fetch messages from their mailbox anytime
LVL 76

Accepted Solution

David Lee earned 500 total points
ID: 39967396
Hi, Guy-in-Transition.

I wrote the article you linked to.  The code in that article depends on CDO which is not supported under Outlook 2010 and later.  For that reason, I've created a new version that should work under outlook 2007 and later.  This version also runs from outside of Outlook, which will allow you to schedule it.  

Follow these instructions to use this solution.

1.  Open Notepad
2.  Copy the code below and paste it into Notepad
3.  Save the file.  You can name it anything you like, but the extension must be .vbs
4.  Using Windows task scheduler, create a task schedule to run at the end of the day
5.  Set the task to run the script saved in step #3.  The script takes two named parameters: State and Message.  The format of the command line will be something like this.

To turn out of office on and set a message

wscript.exe Out-of-Office.vbs /State:on /Message:"I am out of the office until tomorrow morning at 7:00am"

To turn out of office off

wscript.exe Out-of-Office.vbs /State:off

This solution has to run at a computer with Outlook installed.  It is not designed to run at the Exchange server.

'--> Define some constants
	Const olPrimaryExchangeMailbox = 0
	Const olIdentifyByMessageClass = 2
	Const olFolderInbox = 6
	Const PR_OOF_STATE = ""

'--> Define some variables
	Dim strVer, olkApp, olkSes, colArg, strSta, strMsg, bolSta
'--> Get the arguments from the command line
	Set colArg = WScript.Arguments.Named
	strSta = colArg.Item("State")
	strMsg = colArg.Item("Message")
	Select Case LCase(strSta)
		Case "on","out","true"
			bolSta = True
		Case Else
			bolSta = False
	End Select
	If strMsg = "" Then strMsg = "Out of the office"
'--> Connect to Outlook
	Set olkApp = CreateObject("Outlook.Application")
	Set olkSes = olkApp.GetNamespace("MAPI")
	olkSes.Logon olkApp.DefaultProfileName
'--> Set the out of office state
	strVer = GetOutlookVersion()
	SetOutOfOfficeState bolSta, strMsg
'--> Disconnect from Outlook

'--> Clean up objects
	Set olkSes = Nothing
	Set olkApp = Nothing
'--> Terminate the script

Sub SetOutOfOfficeState(bolState, strMessage)
    ' Purpose: Set the state of Out of Office.'
    ' Written: 10/12/2009'
    ' Author:  David Lee'
    ' Outlook: 2007'
    Dim olkIS, olkPA, olkSto
    'On Error Resume Next
    If strVer >= "12.0" Then
        For Each olkIS In olkSes.Stores
            If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            	Set olkSto = olkSes.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
            	olkSto.Body = strMessage
                Set olkPA = olkIS.PropertyAccessor
                olkPA.SetProperty PR_OOF_STATE, bolState
            End If
        MsgBox "The SetOutOfOfficeState method is only available to Outlook 2007 and later", vbExclamation + vbOKOnly
    End If
    On Error GoTo 0
    Set olkIS = Nothing
    Set olkPA = Nothing
    Set olkSto = Nothing
End Sub

Function GetOutlookVersion()
    ' Purpose: Returns the Outlook version in the form xx.x.'
    ' Written: 6/3/2011'
    ' Author:  David Lee'
    ' Outlook: All version'
    Dim arrVersion
    arrVersion = Split(olkapp.Version, ".")
    GetOutlookVersion = arrVersion(0) & "." & arrVersion(1)
End Function

Open in new window

LVL 48

Expert Comment

by:Martin Liss
ID: 40026919
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
LVL 76

Expert Comment

by:David Lee
ID: 40026920
I object.  There is enough information to confirm an answer.  All that's required is to test the code yourself to see that it works as described.

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In-place Upgrading Dirsync to Azure AD Connect
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
This video discusses moving either the default database or any database to a new volume.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question