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

  • by

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:


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
         Exit For
      End If

End Sub

Leave a Reply

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