(Solved) – How to activate Out of Office reply on outlook 2010 using Visual Basics

  • by
(solved)-–-how-to-activate-out-of-office-reply-on-outlook-2010-using-visual-basics

I don’t have access to the exchange server that host our outlook, but I would like to eventually automate my Out of Office based on the days that I’ll be out on a biweekly basis. With help from numerous postings, I was able to set an outlook rule to send a automatic reply on Mon and apply visual basics script to disable this rule when I’m in the office (with my outlook open), but this is not an elegant way because the rule continuously send a reply to the user repeatedly every time when an email is sent to me. How can I activate my Out of Office reply on outlook 2010 using Visual Basics?

Here’s the two great resources that I used:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_outlook-mso_win10/set-up-recurring-out-of-office-auto-reply-for/71dd1fef-ba99-4a2b-be72-7d509e8848eb

https://superuser.com/questions/292426/outlook-2010-how-to-turn-out-of-office-on-automatically-when-outlook-is-closed

This is the script I have on my “ThisOutlookSession” in my “Microsoft Outlook Objects” to enable/disable the rule, “HomeTime” containing my Out Of Office-like message.

Any help will be greatly appreciated. Thanks!


Private Sub Application_Quit()
   SetRuleEnabled True
End Sub

Private Sub Application_Startup()
   SetRuleEnabled False
End Sub

Private Sub SetRuleEnabled(ByVal bEnable As Boolean)
   Dim oSession    As Outlook.NameSpace
   Dim oRule       As Outlook.Rule
   Dim oRules      As Outlook.Rules
   Dim oPA         As Outlook.PropertyAccessor

   Set oSession = Application.Session
   Set oRules = oSession.DefaultStore.GetRules()
   Set oPA = oSession.DefaultStore.PropertyAccessor

   '*** If the Out-Of-Office is already on (eg. holidays, sick leave etc.) 
   '*** then it might be best to force this rule permanently off
   If oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B") Then
      bEnable = False
   End If

   For Each oRule In oRules
      If oRule.Name = "HomeTime" Then
         oRule.Enabled = bEnable
         oRules.Save
         Exit For
      End If
   Next

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *