Prompt button to auto turn on Out of Office

Not open for further replies.


New Member
Outlook version
Outlook 2019 64-bit
Email Account
Office 365 Exchange

I have been working on some VBA to allow me to just click a yes button to turn on my Out of Office when I quit outlook but I can't get it to work.

I'm on Office 365.

Code is as follows:

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
End If
Set objMAPISession = Nothing
End Sub

Can anyone help fix my code for me?



New Member
Outlook version
Outlook 2019 64-bit
Email Account
Office 365 Exchange
Thank you for your reply, I am quite new to VBA and am struggling to work out how to fit that into my code. Would you be able to offer any advice?
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
R Prompt asking the user to send email to folder as *.msg file Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
K VBA to prompt and send a CC Outlook VBA and Custom Forms 6
K VBA - Prompt for reminder date time Outlook VBA and Custom Forms 7
S Have Rule or Quick Step PROMPT for custom FLAG Due/Reminder date Outlook VBA and Custom Forms 3
P Constant Username Password Prompt Using Outlook 2
A Prompt on exit to empty deleted items folder "for all accounts" does not work? Using Outlook 6
C Is there a way to prompt a user before deleting an item? BCM (Business Contact Manager) 4
S Prompt to add for text to existing subject line before sending. Using Outlook 9
S Trying to have a prompt to ask for text to be added to subject before sending. Using Outlook 3
N Prompt for password when sending an email Exchange Server Administration 1
O How to turn off the prompt to permanently delete messages upon exiting? Using Outlook 2
G Outlook keep prompt for log in credential Using Outlook 1
J Deactivate MS Outlook 2007 prompt to make it the default email client Using Outlook 1
O Outlook 2007 SP2 Prompt for Password Exchange Server Administration 3
R Does not prompt for saving or opening attachments when downloading attachment in Outlook 2007. Using Outlook 3
S Continuous password and username prompt in outlook 2007 Using Outlook 1
E Enter Network Password prompt does not accept my password Using Outlook 4
I Prompt before sending contacts to Deleted Items folder Using Outlook 7
B Password prompt for the pst files Using Outlook 9
O OWA 2003 prompt to re-auntenticate when opening up office attachments Using Outlook 10
L outlook 2007 login prompt from old exchange host Using Outlook 3
B outlook 2007 password prompt keeps popping up Using Outlook 1
M Outlook 2007 and Outlook 2010 continues to prompt user for their password Using Outlook 7
E Users get login prompt in Outlook 2007 when accessing Exchange Server 2007 Using Outlook 2
D Credentials Prompt Exchange Server Administration 1
L Strange macro prompt Using Outlook 1
S How to add multiple exchange accounts without password / credential prompt? Using Outlook 5
C Reboot a CAS array member causes Outlook 2010 clients to prompt for credentials. Using Outlook 5
M Email Prompt Outlook VBA and Custom Forms 1
T Prompt for email account Outlook VBA and Custom Forms 1
P Outlook security prompt after installing Add-in Outlook VBA and Custom Forms 3
Q Otlk 2007 does not block when in "always prompt for..." mode Outlook VBA and Custom Forms 2
Q sending mail when Otlook in 'always prompt for user name and passw Outlook VBA and Custom Forms 4
J Outlook 2007 Clients Prompt For Password When Opening Using Outlook 21
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
K Disabling import/export button to restrict PST creation Using Outlook 3
N Which Button Was Clicked on the Ribbonbar Menu Outlook VBA and Custom Forms 2
E Can't accept or decline task (no button appears) Using Outlook 3
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
C iCloud Setting missing Outlook tab and Outlook missing the iCloud refresh button Using Outlook 4
witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
A ScanPST finding errors but no Repair button Using Outlook 2
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1

Similar threads