A user asked if he could turn on Out of Office every time he closed Outlook. While this is not possible using native features built into Outlook, you can use VBA to prompt you to turn on Out of Office when you close Outlook 2007 or Outlook 2003. (It may work with older versions but will not work with newer versions of Outlook.)
This code sample uses the CDO library, which is no longer included with Outlook, beginning with Outlook 2010. It works with (and was tested on) Outlook 2007 and Outlook 2003 but will not work with Outlook 2010 and newer.
Out-of-Office Code
Private Sub Application_Quit() Msg = MsgBox("Turn on Out of Office?", vbYesNo) If Msg <> vbYes Then Exit Sub Set oSession = CreateObject("MAPI.Session") oSession.Logon "", "", False, False ' If you want to set the OOF text. 'oSession.OutOfOfficeText = "OOF reply text." ' Turning on Out of Office oSession.OutOfOffice = True oSession.Logoff Set oSession = Nothing End Sub
Have you found a solution to turn on OOF for Outlook 2016 somewhere else... without using RDO?
No, not at the desktop level.
But... if you have an Microsoft 365 business account (and have the correct permsssions), you can enable OOF using powershell.
Hi, I have tried the above code, but does not work, I am running outlook 2010 (exchange on-line). The code does not error in any way. Is this because of Exchange on-line??
Code runs through fine, but does not toggle turning on / off.
Many thanks,
It's Outlook, not Exchange online - it only works in Outlook 2007 and Outlook 2003 because it uses CDO.
Try this code in Outlook 2010 - it's not working in Outlook 2013 and 2016 though. If you remove the startup macro (so oof is not turned off) you won't see the 'OOF is on' banner - that is only enabled when you go into the automatic reply dialog.
My own preference is to use the option to enable OOF to turn on and off automatically - i set the off time past when I expect to arrive and change the start time. Now to figure out why it doesn't work with 2013+ and to make it work with an appointment reminder.
Private Sub Application_Quit()
' Turns OOF on when you exit Outlook
OutOfOffice True
End Sub
Private Sub Application_Startup()
' Turns OOF off when you open Outlook
OutOfOffice False
End Sub
Sub OutOfOffice(bState As Boolean)
Const PR_OOF_STATE = "https://schemas.microsoft.com/mapi/proptag/0x661D000B"
Dim olStore As Outlook.Store, PA As Outlook.propertyAccessor
For Each olStore In Session.Stores
If olStore.ExchangeStoreType = olPrimaryExchangeMailbox Then
Set PA = olStore.propertyAccessor
PA.SetProperty PR_OOF_STATE, bState
End If
Next
Set olStore = Nothing
Set PA = Nothing
End Sub
IS cdo installed on client or server? Not that I have rights to either, these days. Before I start chasing my IT bod.
However, my original problem was how to paste the end date from my OoF date range into my OoF message (so I only have to remenber to change the date range & the rest is done for me).
Any help on this would be most welcome!
CDO would need to be client side for this to work. I'll see what i can come up with. Exchange 2010 / Outlook 2010 combo lets you schedule OOF - when you go in to turn it off, you can reschedule it and turn it back on.
I'v tried this in Outlook 2010 & get the following error:
Run-time error '-2147221005(800401f3)'
when it gets to:Set OSession = CreateObject("MAPI.Session")
Any ideas?
the error is because cdo is not installed with outlook 2010 - mapi session uses cdo.