dcsimg
Results 1 to 11 of 11

Thread: Set Outlook Out-of-office programatically

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Resolved Set Outlook Out-of-office programatically

    I need to be able to set the Outlook Out-of-office mode automatically, for different start and stop dates/times.

    One user needs the auto-reply to be turned on every Monday and Friday, while another needs every Friday.

    Currently, they have to set this manually, through the Outlook File\Automatic Replies buttons.

    This is a nuisance, and can easily be forgotten, hence the request to automate it.

    We are all using Office 365.

    Thanks in advance for any ideas!
    Last edited by JimOldguy; Jun 20th, 2019 at 03:00 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,558

    Re: Set Outlook Out-of-office programatically

    How do you want this to be triggered? Click a button and choose the OoO pattern? Starting, or exiting Outlook? Other?

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Re: Set Outlook Out-of-office programatically

    Hi,
    If I can get the basic function to work, I'll probably set it up to run at start of Outlook, where it will check for the appropriate day.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Re: Set Outlook Out-of-office programatically

    Hi,
    If I can get the basic function to work, I'll probably set it up to run at start of Outlook, where it will check for the appropriate day.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,449

    Re: Set Outlook Out-of-office programatically

    are you running outlook connected to an exchange server?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Re: Set Outlook Out-of-office programatically

    Yes, Office 365 etc.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,449

    Re: Set Outlook Out-of-office programatically

    If I can get the basic function to work
    Code:
            ' The name of the property whose value is to be returned. 
            Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B" 
             
            ' Set reference to the Stores collection. 
            Set stoItems = olApp.GetNamespace("MAPI").Stores 
             
            ' /* Step through each store object in the stores collection. */ 
            For Each stoItem In stoItems 
                 
                ' /* a primary Exchange mailbox store. */ 
                If stoItem.ExchangeStoreType = olPrimaryExchangeMailbox Then 
                    'Obtain an instance of PropertyAccessor class. 
                    Set olPropAccessor = stoItem.PropertyAccessor 
                     
                    ' Get the Out of Office state. 
                    blnOOFState = olPropAccessor.GetProperty(PR_OOF_STATE) 
                    ' /* Toggle the Out of Office state if the old state is not the same as the given state. */ 
                    If blnOOFState <> OOFState Then Call olPropAccessor.SetProperty(PR_OOF_STATE, OOFState)
                End If 
                 
            Next
    from https://gallery.technet.microsoft.co...ffice-bc0edb1e

    where OOFSTATE = true or false, you will need to make sure all your application constants are valid, if there are multiple store i would include exit for
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Re: Set Outlook Out-of-office programatically

    Thank you, Westconn1, that is exactly what I needed.

    I've followed your link, and downloaded the vbscript there. I believe I now have all that I need.

    Thanks again,

    Jim

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,449

    Re: Set Outlook Out-of-office programatically

    i did not see any reason to test the current state before changing, just set to the desired state anyway

    while it is useful to know how to test the current state, it did not seem to be required for the code to work as required
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2015
    Posts
    39

    Resolved Re: Set Outlook Out-of-office programatically

    I've looked in detail at the script listed above, and decided not to go with it.
    The script sets up scheduled tasks, to run at the specified time, to toggle the state of the Out Of Office feature.
    This will work just fine for one of my users, who works in the office, 9 - 5.
    The other user is mobile, and there is slim chance that her laptop will be running at the times that the scheduled tasks would be set to run.

    Instead, I have set up two rules on the Exchange, whereby any emails received, for the specific addressee, between specified start and stop days, will receive an automatic Out-of-Office reply. Unless the received message is itself an automatic reply. (Don't want to kick off any email storms!)

    Thanks to all who responded and helped.

    Jim

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,449

    Re: Set Outlook Out-of-office programatically

    I've looked in detail at the script listed above,
    i only posted the part of the code i though relevant to you, none of the scheduling part

    i agree your simple solution is probably much better, though you can call a vba macro from a rule if that is ever of any use
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width