2015-02-12 53 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