我想使用VBA创建规则,而不是在规则中运行脚本,这会在收到来自特定域的电子邮件时添加类别(红色)。我可以计算接收和特定域部分,但我正在努力使用正确的类别VBA语法。类别的颜色为红色,类别的名称为" SPAM"。这是我最近的尝试:
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 :(得分:0)
您只需将类别名称设置为MailItem类的Categories属性即可。类别是已分配给Outlook项目的分隔的类别名称字符串。此属性使用Windows注册表中HKEY_CURRENT_USER \ Control Panel \ International下的值名称sList中指定的字符作为多个类别的分隔符。
mailItem.Categories = "SPAM"
答案 1 :(得分: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