Outlook 2016 script rules RRS feed

All replies

  • Hi ilyasma,

    Thanks for visiting our forum.

    Then here we mainly focus on general questions about Outlook client. Since your query is related to script, we'll move your thread to the following dedicated MSDN forum for Outlook for better response:

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,
    Yuki Sun

    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact

    Thursday, April 27, 2017 8:20 AM
  • Hello,

    The Outlook object model allows to create event handlers where you can handle items and move them programmatically or just create a rule for doing that like users do in the Outlook UI, for example:

    Sub CreateRule() 
        Dim colRules As Outlook.Rules 
        Dim oRule As Outlook.Rule 
        Dim colRuleActions As Outlook.RuleActions 
        Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction 
        Dim oFromCondition As Outlook.ToOrFromRuleCondition 
        Dim oExceptSubject As Outlook.TextRuleCondition 
        Dim oInbox As Outlook.Folder 
        Dim oMoveTarget As Outlook.Folder 
        'Specify target folder for rule move action 
        Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
        'Assume that target folder already exists 
        Set oMoveTarget = oInbox.Folders("Eugene") 
        'Get Rules from Session.DefaultStore object 
        Set colRules = Application.Session.DefaultStore.GetRules() 
        'Create the rule by adding a Receive Rule to Rules collection 
        Set oRule = colRules.Create("Eugene's rule", olRuleReceive) 
        'Specify the condition in a ToOrFromRuleCondition object 
        'Condition is if the message is from "Dan Wilson" 
        Set oFromCondition = oRule.Conditions.From 
        With oFromCondition 
            .Enabled = True 
            .Recipients.Add ("Eugene Astafiev") 
        End With 
        'Specify the action in a MoveOrCopyRuleAction object 
        'Action is to move the message to the target folder 
        Set oMoveRuleAction = oRule.Actions.MoveToFolder 
        With oMoveRuleAction 
            .Enabled = True 
            .Folder = oMoveTarget 
        End With 
        'Specify the exception condition for the subject in a TextRuleCondition object 
        'Exception condition is if the subject contains "fun" or "chat" 
        Set oExceptSubject = _ 
        With oExceptSubject 
            .Enabled = True 
            .Text = Array("fun", "chat") 
        End With 
        'Update the server and display progress dialog 
    End Sub 

    See Create a Rule to Move Specific E-mails to a Folder for more information.

    Also you may find the Getting Started with VBA in Outlook 2010 article helpful.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, April 27, 2017 9:47 AM