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
objMAPISession.Logoff
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
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.