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

How to handle Account Condition Properties Rules in Outlook VBA

我正在尝试向 VBA 创建的一组 Outlook 规则添加 "from account" 条件。帐户的 DisplayName 是:abcd@abcd.com,AccountType 是:0,Class 是: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 资源,非常感谢您的帮助。

感谢 Eugene,我找到了解决方法:

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 class 的 Account 属性 设置一个有效的帐户对象(参见 Namespace.Accounts)- 表示用于评估规则条件的帐户。

参阅 Specifying Rule Conditions for more information. Also you may find the How to: Create a Rule to Move Specific E-mails to a Folder 文章很有帮助。

试试引号。

Account.DisplayName Property (Outlook)

"Returns a String representing the display name of the e-mail Account. Read-only."

.Account.DisplayName = "abcd@abcd.com"

编辑 2015 年 02 月 15 日

如果你想在某处使用Account.DisplayName,它是作为读取模式的字符串。

这个除了Eugene的"It seems you need to choose the account from the Accounts collection with the specified email address and then set it to the rule conditions."导致setting/identifying以外的账号。

不用说这段代码可以在规则情况下使用,它会是这样的:

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