Reputation: 91497
According to the documentation, I should be able to specify a condition in my Outlook Rule that matches based on a partial string match of the sender address by specifying the text to match in TextRuleCondition.Text
on the condition of type olConditionSenderAddress
:
But, I cannot find the appropriate property to set within the Rule.Conditions
object. If I enumerate a newly created rule's conditions, there is no existing condition of type TextRuleCondition
having ConditionType == olConditionSenderAddress
. The only condition with the correct ConditionType
is an AddressRuleCondition
, which has no Text
property.
How do I programmatically specify a condition in an Outlook 2010 rule where the sender address contains a certain string?
Upvotes: 3
Views: 1949
Reputation: 2590
You can use Conditions.SenderAddress
rule condition and use its address property like bellow:
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim oAddressRuleCondition As Outlook.AddressRuleCondition
Set colRules = Application.Session.DefaultStore.GetRules()
Set oRule = colRules.Create("Sender Rule", olRuleReceive)
Set oAddressRuleCondition = oRule.Conditions.SenderAddress
With oAddressRuleCondition
.Enabled = True
.Address = Array("example")
End With
.....
colRules.Save
Upvotes: 4