使用Outlook 2010,我想添加"停止处理更多规则"一个规则。
我使用Outlook中的常规规则界面定义了规则。该规则是许多规则中的一个,所有这些规则都有#34;停止处理更多规则"设置除了这一个。该规则运行脚本。这个没有"停止处理更多规则"。在脚本运行之前,我不知道是否要停止处理更多规则。我不想在VBA中更改此规则(或任何规则),只需在VBA脚本中决定是否停止处理更多规则。
代码I使用(向下编辑)
Public Sub checkforvalidfiletype(Item As Outlook.MailItem)
Dim olkAtt As Outlook.Attachment
Dim orule As Outlook.Rules
Dim oRuleAction As Outlook.RuleAction
'Check each attachment
Stop
For Each olkAtt In Item.Attachments
'If the attachment's file name ends with .xls .csv or .xlsx
If Right(LCase(olkAtt.FileName), 4) = ".xls" Or Right(LCase(olkAtt.FileName), 4) = ".csv" Or Right(LCase(olkAtt.FileName), 5) = ".xlsx" Then
'then assign it to the Unknown .xls .xlxs or .csv to be processed category
Item.Categories = "Unknown .xls .xlxs or .csv to be processed"
Item.Save
'and stop processing more rules
Set oRuleAction = orule.Actions.Stop
With oRuleAction
.Enabled = True
End With
'No need to check any of this message's remaining attachments (just one valid attachment is enough for us to want to know about it)
Exit For
End If
Next
Set olkAtt = Nothing
End Sub
我遇到了运行时错误' 91' Set oRuleAction = orule.Actions.Stop
行上的对象变量或块变量未设置错误。 (我引用了正确的对象库。)
答案 0 :(得分:0)
你现在可能已经想到了这一点。从您发布的内容来看,oRule对象未设置,您可能需要Rule对象,您可以从中设置Rule对象...
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
以下示例性类似代码: https://msdn.microsoft.com/en-us/library/office/ff867254(v=office.14).aspx