I would like to add a macro to Outlook 2007 that asks me when I shut it down if I want to turn the Out of Office Assistant on, and then asks me when I open Outlook if I want to turn Out of Office Assistant off. I've found instructions for creating the prompt at close (at Outlook 2010: How to turn Out of Office on automatically when Outlook is closed? and http://itknowledgeexchange.techtarget.com/itanswers/automating-out-of-office/) but I don't know how to write a macro for the prompt at open.
Private Sub Application_Quit() OutOfOffice True End Sub
This is the part you are interested in.
Private Sub Application_Startup() 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
There is a note "not tested the code with Outlook 2010."
As well " 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."