none
VBA - object model for Rules RRS feed

  • Question

  • I am using VBA to get familiar with the OL 2010 object model, specifically the section relating to Outlook Rules. In a message store in Outlook 2010 32-bit (client), I have ~200 rules set, most of which move the mail to some folder (there are ~10 separate PST files aggregated into a single profile), plus a few that are forwarded to one or more recipients.

    My crude code is like this -

        Set st = Application.Session.DefaultStore  

      ' get rules
      Set myRules = st.GetRules
      ' iterate all the rules
      For Each rl In myRules
        ' determine if it’s an Inbox rule
        If rl.RuleType = olRuleReceive Then
          ruleList = ruleList & vbCrLf & "{" & CStr(rl.ExecutionOrder) & "}|" & rl.Name & IIf(rl.Enabled, "", " {DISABLED}")
          ' Get some other useful stuff for each Rule
          For Each oAction In rl.Actions
             If oAction.Enabled = True Then
                If oAction.ActionType = olRuleActionMoveToFolder Then
                   ruleList = ruleList & vbCrLf & vbTab & "MoveToFolder: " & oAction.Folder.FolderPath
                   'Debug.Print ("Move to folder: " & oAction.Folder.FolderPath)
                End If
             If oAction.ActionType = olRuleActionForwardAsAttachment Then
                ' Debug.Print ("FW: " & olRecipients)
             End If
             
             End If
          Next
               
        End If
      Next

    I'm stumped on how to get the one or more recipients (email addresses) that my Rules use. The bold code above prints a number not an email address.

    What do I need to get the address?

    Tuesday, July 17, 2012 7:47 AM

Answers

  • thx Damian - almost.

    It is the address to which I am forwarding that I need to print.

    I thought   rl.Conditions.ToOrCc.Recipients.Item(1).AddressEntry  would be the property, but not so.

    Here is a capture from the OL2010 Rules Wizard - it is the address after 'forward it to' which I cannot find a proprty for.

    duh - of course it is an Action, not a Condition, that is what I want.

    rl.Actions.ForwardAsAttachment.etc
    • Marked as answer by gxdata Tuesday, July 17, 2012 10:50 AM
    Tuesday, July 17, 2012 10:28 AM

All replies

  • you are printing value of enumeration. What you need (what i think i understood from your descrption) is to check which condition in rule is enabled and read its recipients, something like:

    rl.Conditions.From.Recipients.Item(1).AddressEntry

    (assuming your condition is on From address, etc.)

    Tuesday, July 17, 2012 9:36 AM
  • thx Damian - almost.

    It is the address to which I am forwarding that I need to print.

    I thought   rl.Conditions.ToOrCc.Recipients.Item(1).AddressEntry  would be the property, but not so.

    Here is a capture from the OL2010 Rules Wizard - it is the address after 'forward it to' which I cannot find a proprty for.

    Tuesday, July 17, 2012 10:23 AM
  • thx Damian - almost.

    It is the address to which I am forwarding that I need to print.

    I thought   rl.Conditions.ToOrCc.Recipients.Item(1).AddressEntry  would be the property, but not so.

    Here is a capture from the OL2010 Rules Wizard - it is the address after 'forward it to' which I cannot find a proprty for.

    duh - of course it is an Action, not a Condition, that is what I want.

    rl.Actions.ForwardAsAttachment.etc
    • Marked as answer by gxdata Tuesday, July 17, 2012 10:50 AM
    Tuesday, July 17, 2012 10:28 AM
  • then you need rl.Actions.ForwardAsAttachment.Recipients... (you know the drill)
    Tuesday, July 17, 2012 10:30 AM
  • Apply this rule after the message arrives received "after Sunday, January 01, 2012 and before Monday, December 31, 2012 move it to the “Archive” folder.
    - it is "received in a specific date span" I cannot find a property for rl.Conditions.?.

    • Edited by Pero Peric Tuesday, January 29, 2013 7:08 AM
    Tuesday, January 29, 2013 7:08 AM
  • Take a look at: http://msdn.microsoft.com/en-us/library/office/ff867147.aspx

    The date range is not exposed in the object model.


    http://www.saberman.com

    Sunday, December 8, 2013 5:52 AM