如何在Outlook VBA中处理帐户条件属性规则

如何在Outlook VBA中处理帐户条件属性规则,vba,outlook,account,rules,Vba,Outlook,Account,Rules,我正在尝试将“来自帐户”条件添加到由VBA创建的一组Outlook规则中。帐户的显示名为:abcd@abcd.com,AccountType为:0,类为:105 Dim oAccountRuleConditionSubscribe As Outlook.AccountRuleCondition Dim oRuleNew As Outlook.Rule Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account Wit

我正在尝试将“来自帐户”条件添加到由VBA创建的一组Outlook规则中。帐户的显示名为:abcd@abcd.com,AccountType为:0,类为:105

Dim oAccountRuleConditionSubscribe As Outlook.AccountRuleCondition
Dim oRuleNew As Outlook.Rule

Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account
    With oAccountRuleConditionSubscribe
    .Enabled = True
    .Account.DisplayName = abcd@abcd.com
    End With
以上是我能想到的最新版本,但它仍然不需要abcd@abcd.com作为有效的帐户引用。我已经用尽了所有教程、词汇表和MSDN资源,非常感谢您的帮助

多亏了尤金,我找到了一个解决办法,包括:

Dim oAccountRuleConditionSubscribe As Outlook.AccountRuleCondition
Dim oRuleNew As Outlook.Rule
Dim OutApp As Outlook.Application
Set OutApp = CreateObject("Outlook.Application")

    Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account
    With oAccountRuleConditionSubscribe
        .Enabled = True
        .Account = OutApp.Session.Accounts.item(2)
    End With

但是我仍然很难通过它的显示名来识别这个帐户

有什么建议吗

.Account.DisplayName=abcd@abcd.com

相反,您需要为AccountRuleCondition类的属性设置一个有效的account对象(请参见Namespace.Accounts),account对象表示用于评估规则条件的帐户

有关更多信息,请参阅。你也会发现这篇文章很有帮助

试试引号

“返回表示电子邮件帐户显示名称的字符串。只读。”

编辑2015 02 15

如果您想在某个地方使用Account.DisplayName,则在读取模式下它将作为字符串

除了Eugene的“您似乎需要从Accounts集合中选择具有指定电子邮件地址的帐户,然后将其设置为规则条件”之外,还需要设置/标识with之外的帐户

不用说,该代码可以在规则情况下使用,它将类似于:

For Each olAcc In Accounts
    If olAcc.DisplayName = "abcd@abcd.com" then
        ' some rules code here
        Exit For
    End if
Next olAcc

编辑2015 02 15-结束

我遇到了同样的问题,并找到了解决方案

Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account
With oAccountRuleConditionSubscribe
  .Enabled = True
  Set .Account = OutApp.Session.Accounts.item("abc@def.com")
End With

谢谢你,尤金。我编辑了原始消息以说明进度。我还没有到那里。你需要在哪里识别帐户?您到底需要实现什么?您似乎需要从Accounts集合中选择具有指定电子邮件地址的帐户,然后将其设置为规则条件。我说得对吗?是的,你说得对。我想使用DisplayName来选择它,而不是item(#)。但是我仍然很难通过DisplayName来识别帐户。-你到底在找什么???在stackoverflow上发布之前试过了。我得到“编译错误。无法分配到只读属性”。真的吗?是否无法创建简单、直接的.Account.DisplayName=”abcd@abcd.com“相当于?为什么我必须通过循环列出所有帐户?
Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account
With oAccountRuleConditionSubscribe
  .Enabled = True
  Set .Account = OutApp.Session.Accounts.item("abc@def.com")
End With