2015-02-24 20 views
1

我想用VBA创建规则,而不是在规则中运行脚本,该规则将为来自特定域的电子邮件添加类别(红色)接收。我可以指出接收和特定域的一部分,但我正在努力使用正确的类别VBA语法。类别的颜色是红色,类别的名称是“SPAM”。这是我最近的尝试:使用VBA创建规则,在收到邮件时将类别添加到电子邮件

Dim oRuleNew As Outlook.Rule 
Dim oCategoryRuleConditionSpam As Outlook.CategoryRuleCondition 

Set oCategoryRuleConditionSpam = oRuleNew.Conditions.Category 
With oCategoryRuleConditionSpam 
    .Enabled = True 
    .Categories = "SPAM" 
End With 

基本上我找不出如何将正确的值分配给.Categories ..任何帮助将非常感激。

也试过: .Categories.Add( “SPAM”)

其实,或许下面是更适合的任务:

Dim oRuleNew As Outlook.Rule 
Dim oCategoryRuleActionSpam As Outlook.RuleAction 

Set oCategoryRuleActionSpam = oRuleNew.Action.AssignToCategory 
With oCategoryRuleActionSpam 
    .Enabled = True 
    .Categories = "SPAM" 
End With 

但现在我收到错误13 :(

找到了!

Dim oRuleNew As Outlook.Rule 
Dim oCategoryRuleActionSpam As Outlook.RuleAction 
Dim aCat(0) As String 

aCat(0) = "SPAM" 
Set oCategoryRuleActionSpam = oRuleNew.Action.AssignToCategory 
With oCategoryRuleActionSpam 
    .Enabled = True 
    .Categories = aCat 
End With 

回答

0

你只需要设置的美食血腥的名字给MailItem类的Categories属性。类别是已分配给Outlook项目的分类名称的分隔字符串。此属性使用在Windows注册表中的HKEY_CURRENT_USER \ Control Panel \ International下的值名称sList中指定的字符作为多个类别的分隔符。

mailItem.Categories = "SPAM" 
+0

嗨尤金,再次感谢您的帮助。不幸的是,它返回错误438 :( – clippertm 2015-02-25 02:31:49

+0

也名字已经存在(垃圾邮件,红色) – clippertm 2015-02-25 02:38:16

+0

它看起来像邮件已经标记了类别,我是对吗? – 2015-02-25 08:08:22

0

发现它!

Dim oRuleNew As Outlook.Rule 
Dim oCategoryRuleActionSpam As Outlook.RuleAction 
Dim aCat(0) As String 

aCat(0) = "SPAM" 
Set oCategoryRuleActionSpam = oRuleNew.Action.AssignToCategory 
With oCategoryRuleActionSpam 
    .Enabled = True 
    .Categories = aCat 
End With 
+0

你需要创建一个规则? – 2015-02-25 08:10:27

相关问题