在Outlook VBA中批量编辑from条件

时间:2019-05-31 15:52:41

标签: vba outlook

我有很多规则。我想与我的队友分享,但是有一些条件需要改变。他们将需要将“从”条件更改为自己。

Sub CHANGERULES()
    Dim objStores As Outlook.Stores
    Dim objStore As Outlook.Store
    Dim objRules As Outlook.rules
    Dim i As Long
    Dim objRule As Outlook.Rule
    Dim objrulecondition As Outlook.ToOrFromRuleCondition

    Set objRules = Application.Session.DefaultStore.GetRules()

        For i = objRules.Count To 1 Step -1
            Set objRule = objRules(i)
            For Each objrulecondition In objRule.Conditions.From
                   If objrulecondition.Enabled = True Then
                      objrulecondition.Recipients.RemoveAll
                      objrulecondition.Recipients.Add ("xyz")
                      objrulecondition.Recipients.ResolveAll
                      On Error Resume Next
                      objRules.Save
                      Exit For
                   End If
            Next
       Next i
End Sub

在运行时错误'438'对象在“对于每个”行中均不支持此属性或方法。

1 个答案:

答案 0 :(得分:0)

由于某种原因,当您使用'''objrulecondition.recipients.remove'''时,它将指定索引值而不是字符串/变量值。因此删除电子邮件的解决方案应该是

objrulecondition.recipeints.remove (1)