none
Enumeration Existing Rules Using VBA -- Cannot Access Text for an olConditionSenderAddress Rule RRS feed

  • Question

  • Outlook 2010 with all patches

    I have set olConditions to the current rules conditions collection.  I then enumerate through them and process the ones that are enabled.  When I get to a olConditionSenderAddress condition type I try to access the text array and VBA throws:
           Object doesn't support this property or method
    I reduced the code to just trying to display the first text string and it bombs:

                For nCondition = 1 To olConditions.Count
                    Set olCondition = olConditions(nCondition)
                    If (olCondition.Enabled) Then
                        Debug.Print "     " & solRuleCondition(olCondition.ConditionType)
                        Select Case olCondition.ConditionType
                            Case olConditionSenderAddress           '   Sender address contains words specified in TextRuleCondition.Text.
                                Debug.Print olCondition.Text(0)        '    Throws error here

    The description of the rule that my code dies on is:

    Apply this rule after the message arrives
    with @emails.skype.com in the sender's address
    move it to the Skype folder
     and stop processing more rules

    According to: http://msdn.microsoft.com/en-us/library/office/ff867147.aspx
    you can not only enumerate all of the Sender Adress condtition you can create the rule and conditions.  So what am I doing wrong?


    http://www.saberman.com

    Sunday, December 8, 2013 5:51 AM

Answers

  • Actually it is:
    ?TypeName(olCondition)
    AddressRuleCondition

    Dim olAddressRuleCondition As Outlook.AddressRuleCondition

    The property is the Address property which is a string array.

    I finally used:
                                Case olConditionSenderAddress           '   Sender address contains words specified in TextRuleCondition.Text.
                                    Set olAddressRuleCondition = olCondition
                                    For nIndex = LBound(olAddressRuleCondition.Address) To UBound(olAddressRuleCondition.Address)
                                        Debug.Print "     " & "     " & olAddressRuleCondition.Address(nIndex)

    The comment is from: http://msdn.microsoft.com/en-us/library/office/ff867147.aspx
    which says:

    Condition                                                                                              Constant in olRuleConditionType
    Sender address contains words specified in TextRuleCondition.Text.  olConditionSenderAddress

    It appears the documentation needs to be fixed.

    http://www.saberman.com

    Monday, December 9, 2013 2:34 AM

All replies

  • Hello saberman,

    The RuleCondition class doesn't provide the Text property. Instead, you need to get an instance of the TextRuleCondition class which is actually derived from the RuleCondition class. To get an instance of the required class you can use the following properties of the RuleConditions class: Body, BodyOrSubject, MessageHeader, and Subject . One of them of them (I believe the Subject) should return a valid instance of the TextRuleCondition class. After you can get a value of the Text property.

    You can read more about rules in the Specifying Rule Conditions article in MSDN.

    Sunday, December 8, 2013 10:44 AM
  • For the olConditionSenderAddress condition, you will have SenderInAddressListRuleCondition object (you can use TypeName(olCondition) to check the rule class name).

    SenderInAddressListRuleCondition exposes the AddressList property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Sunday, December 8, 2013 4:59 PM
  • Actually it is:
    ?TypeName(olCondition)
    AddressRuleCondition

    Dim olAddressRuleCondition As Outlook.AddressRuleCondition

    The property is the Address property which is a string array.

    I finally used:
                                Case olConditionSenderAddress           '   Sender address contains words specified in TextRuleCondition.Text.
                                    Set olAddressRuleCondition = olCondition
                                    For nIndex = LBound(olAddressRuleCondition.Address) To UBound(olAddressRuleCondition.Address)
                                        Debug.Print "     " & "     " & olAddressRuleCondition.Address(nIndex)

    The comment is from: http://msdn.microsoft.com/en-us/library/office/ff867147.aspx
    which says:

    Condition                                                                                              Constant in olRuleConditionType
    Sender address contains words specified in TextRuleCondition.Text.  olConditionSenderAddress

    It appears the documentation needs to be fixed.

    http://www.saberman.com

    Monday, December 9, 2013 2:34 AM