2015-02-12 81 views
0

我试图将一个“从帐户”条件添加到由VBA创建的一组Outlook规则。该帐户的显示名称是:[email protected],ACCOUNTTYPE是:0和Class是:105如何处理Outlook中的帐户条件属性规则VBA

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

Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account 
    With oAccountRuleConditionSubscribe 
    .Enabled = True 
    .Account.DisplayName = [email protected] 
    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 

但我仍然在努力通过其displayName OT identigy的帐户。

任何指针?

+0

您需要在哪里确定帐户?你究竟需要实现什么?您似乎需要从Accounts集合中选择具有指定电子邮件地址的帐户,然后将其设置为规则条件。我对吗? – 2015-02-13 09:07:07

+0

是的,你是对的。我想选择它使用DisplayName,而不是项目(#)。 – clippertm 2015-02-16 00:33:36

+0

但我仍然在通过其DisplayName来识别账户。 - 你到底在找什么? – 2015-02-16 14:05:25

回答

0

尝试引用。

Account.DisplayName Property (Outlook)

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

.Account.DisplayName = "[email protected]" 

编辑2015年02 15

如果你想用的地方Account.DisplayName,它是在读模式的字符串。

这除了尤金的“你似乎需要从Accounts集合中选择具有指定电子邮件地址的帐户,然后将其设置为规则条件。”导致设置/识别With之外的帐户。

没有说这个代码可以在规定情况下使用,这将是这样的:

For Each olAcc In Accounts 
    If olAcc.DisplayName = "[email protected]" then 
     ' some rules code here 
     Exit For 
    End if 
Next olAcc 

编辑2015年02 15 - 结束

+0

在发布到stackoverflow之前尝试过。我得到“编译错误。不能分配给只读属性”。 – clippertm 2015-02-16 01:53:50

+0

认真吗?有没有办法有一个简单的,直接.Account.DisplayName =“[email protected]”等效?为什么我必须通过循环列出所有帐户? – clippertm 2015-02-18 02:45:06

0

.Account.DisplayName = [email protected]

相反,你需要设置一个有效的帐户对象(见Namespace.Accounts)到AccountRuleCondition类的Account属性 - 帐户对象代表用于评估规则条件的帐户。

请参阅Specifying Rule Conditions了解更多信息。您还可以找到How to: Create a Rule to Move Specific E-mails to a Folder文章有帮助。

+0

谢谢尤金。我编辑了原始信息以说明进展情况。我还没有。 – clippertm 2015-02-13 05:14:57

0

我有同样的问题,找到了解决办法。

Set oAccountRuleConditionSubscribe = oRuleNew.Conditions.Account 
With oAccountRuleConditionSubscribe 
    .Enabled = True 
    Set .Account = OutApp.Session.Accounts.item("[email protected]") 
End With