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
' Optional: Set the body text.
'oSession.OutOfOfficeText = "The OOF reply text."
' Turning on Out of Office
oSession.OutOfOffice = True
oSession.Logoff
Set oSession = Nothing
End Sub