指定规则条件Specifying Rule Conditions

Rules 对象模型可支持最常用的规则操作和条件。The Rules object model supports the most commonly used rule actions and conditions. 每个**Rule** 对象都有一个**Actions** 属性, 该属性表示该规则的规则操作, 以及一个**条件** 属性和一个代表该规则的条件的**异常** 属性。Each Rule object has an Actions property that represents the rule actions for that rule, as well as a Conditions property and an Exceptions property that represent the conditions for that rule. 本主题介绍 Rules 对象模型如何支持规则条件。This topic describes how the Rules object model supports rule conditions.

规则的规则条件由**RuleConditions** 集合对象表示。Rule conditions for a rule are represented by a RuleConditions collection object. RuleConditions对象具有与规则中的每个常用规则条件相对应的属性。A RuleConditions object has properties that correspond to each commonly used rule condition in a rule. 例如, 如果某个规则指定了两个条件, 则该邮件非常重要, 主题包含某些词, 然后该规则的RuleConditions集合对象的**重要性** 和**subject** 属性将返回相应的规则启用的条件对象 (已启用的 RuleConditionTrue)。For example, if a rule specifies two conditions - the message is important and the subject contains certain words - then the Importance and Subject properties of the rule's RuleConditions collection object will return respective rule condition objects that are enabled (RuleCondition.Enabled is True).

不会在相应的**RuleCondition** 对象 (RuleCondition. enabledFalse) 中启用规则中未指定的条件。Conditions that are not specified in a rule will not be enabled in the corresponding RuleCondition object (RuleCondition.Enabled is False). 规则条件对象由rulecondition对象或从rulecondition对象派生的自定义对象表示。Rule condition objects are represented by either the RuleCondition object or customized objects derived from the RuleCondition object. 在最后一个示例中, RuleConditions属性将返回一个**ImportanceRuleCondition** 对象, RuleConditions属性将返回一个**textrulecondition.text** 对象, 这两个对象都是派生的从RuleCondition对象。In the last example, the RuleConditions.Importance property will return an ImportanceRuleCondition object, and the RuleConditions.Subject property will return a TextRuleCondition object, both of which are derived from the RuleCondition object. RuleCondition对象及其派生对象具有ConditionType属性, 该属性将指示规则条件的类型, 例如, ImportanceRuleCondition 将指示值olConditionImportance和**textrulecondition.text** 将指示textruleconditionolconditionsubjecttextrulecondition.conditiontypeThe RuleCondition object and its derived objects have the ConditionType property that will indicate the type of the rule condition, for example, ImportanceRuleCondition.ConditionType will indicate the value olConditionImportance, and TextRuleCondition.ConditionType will indicate olConditionSubject.

请注意, rules 对象模型使用 "规则和通知向导" 维护部分奇偶校验。Note that the Rules object model maintains partial parity with the Rules and Alerts Wizard. 这意味着, 虽然您可以使用向导来创建指定您在向导中看到的任何操作和条件的规则, 但您可以通过编程方式创建规则, 这些规则使用某些但不是所有这些操作和条件。This means that while you can use the Wizard to create rules that specify any action and condition that you see in the Wizard, you can programmatically create rules that use some but not all of these actions and conditions. rules 对象模型为向导创建的规则支持的条件, 而不是由对象模型创建的规则的一个示例是特定敏感度级别的邮件。An example of a condition that the Rules object model supports for rules created by the Wizard but not for those created by the object model is messages of certain level of sensitivity. 您可以使用向导创建指定敏感度的规则作为条件。You can use the Wizard to create a rule specifying sensitivity as a condition.

使用 rules 对象模型, 可以枚举 rules 集合中的每个规则的**** 规则集合中的此类规则, **** 枚举其RuleConditions集合, 并查找已启用的规则条件以进行敏感度。Using the Rules object model, you can enumerate this kind of rule in the Rules collection - for each rule in the Rules collection, enumerate its RuleConditions collection and look for an enabled rule condition for sensitivity. 在代码中, 这会对Rules集合中的每个规则 (使用从1到**RuleConditions** 的_索引_枚举**RuleConditions (Index))** 进行枚举, 并查找已启用的条件以使用**ConditionType** 等于olConditionSensitivityIn code, this would mean for each rule in the Rules collection, enumerate RuleConditions.Item(Index) using the Index from 1 to RuleConditions.Count and look for an enabled condition with RuleCondition.ConditionType equal to olConditionSensitivity. 您还可以在规则中启用或禁用此类规则条件。You can also enable or disable such a rule condition in a rule. 但是, 不能以编程方式创建指定olConditionSensitivity条件的规则。However, you cannot programmatically create a rule that specifies the olConditionSensitivity condition.

下表列出了 "规则和通知向导" 支持的所有规则条件, 以及在使用 Rules 对象模型创建规则时是否支持每个规则条件。The following table lists all the rule conditions supported by the Rules and Alerts Wizard, and whether each rule condition is supported when creating a rule using the Rules object model. rules 对象模型所创建的规则中不支持的规则条件仅支持以编程方式枚举, 并在规则和通知向导创建的现有规则中启用或禁用。A rule condition that is not supported in rules created by the Rules object model is supported only for programmatic enumeration and enabling or disabling in existing rules created by the Rules and Alerts Wizard. 该表还显示规则条件是否适用于具有olRuleReceive规则类型或olRuleSend规则类型的规则, 或同时适用于这两者。The table also shows whether the rule condition applies to rules with the olRuleReceive rule type or olRuleSend rule type, or both.

注释 您不能启用或禁用类型olConditionOtherMachine的规则条件。Note You cannot enable or disable a rule condition of the type olConditionOtherMachine. 此类规则条件指示规则只能在特定计算机上运行,但当前的计算机不是该计算机。This type of rule condition indicates that the rule can run only on a certain computer, but the current computer is not that computer. 在一台计算机上创建规则并启用规则条件olConditionLocalMachineOnly时, 会出现这种情况, 指示该规则只能在该计算机上运行。This happens when the rule is created on one computer and the rule condition olConditionLocalMachineOnly is enabled, indicating that the rule can run only on that computer. 在某些情况下,如果启用另一个规则条件(如, olConditionAccount),则会自动设置 olConditionLocalMachineIn certain cases, olConditionLocalMachine is automatically set as a result of enabling another rule condition such as olConditionAccount. 当您在另一台计算机上运行相同的规则时, 规则将显示条件olConditionOtherMachine已启用。When you run the same rule on another computer, the rule will show that the condition olConditionOtherMachine is enabled.

ConditionCondition olRuleConditionType 中的常量Constant in olRuleConditionType 以编程方式创建新规则时是否受支持?Supported when creating new rules programmatically? 是否适用于 olRuleReceive 规则?Apply to olRuleReceive rules? 是否适用于 olRuleSend 规则?Apply to olRuleSend rules?
帐户是在**AccountRuleCondition** 中指定的帐户。Account is the account specified in AccountRuleCondition.Account. olConditionAccountolConditionAccount Yes Yes Yes
为邮件分配了类别。Message is assigned any category. 与 olconditionanycategoryrulecondition.conditiontypeolConditionAnyCategory Yes Yes Yes
正文包含**textrulecondition.text** 中指定的单词。Body contains words specified in TextRuleCondition.Text. textruleconditionolconditionbodytextrulecondition.conditiontypeolConditionBody Yes Yes Yes
正文或主题包含 textrulecondition.text 指定的单词 Body or subject contains words specified by TextRuleCondition.Text. textruleconditionolconditionbodyorsubjecttextrulecondition.conditiontypeolConditionBodyOrSubject Yes Yes Yes
为邮件分配了在**CategoryRuleCondition** 中指定的一个或多个类别。Message is assigned the category or categories specified in CategoryRuleCondition.Categories. olConditionCategoryolConditionCategory Yes Yes Yes
邮件的 "抄送" 框中有我的姓名。Message has my name in the Cc box. 与 olconditionccrulecondition.conditiontypeolConditionCc Yes Yes
在 x 和 y 之间收到邮件,其中 x 和 y 是整数值。Message was received between x and y, where x and y are Integer values. olConditionDateRangeolConditionDateRange No 必需Yes Yes
将邮件标记为需执行指定操作。Message is flagged for the specified action. olConditionFlaggedForActionolConditionFlaggedForAction No 必需Yes Yes
邮件使用 FormNameRuleCondition 中指定的窗体。 FormNameMessage uses the form specified in FormNameRuleCondition.FormName. olConditionFormNameolConditionFormName Yes Yes Yes
发件人位于**ToOrFromRuleCondition** 中指定的收件人列表中。Sender is in the recipient list specified in ToOrFromRuleCondition.Recipients. olConditionFromolConditionFrom Yes Yes No
邮件从任何 RSS 订阅生成。Message is generated from any RSS subscription. 与 olconditionfromanyrssfeedrulecondition.conditiontypeolConditionFromAnyRssFeed Yes Yes No
邮件从指定的 RSS 订阅生成。Message is generated from a specified RSS subscription. olConditionFromRssFeedolConditionFromRssFeed Yes Yes No
邮件包含附件。Message has an attachment. 与 olconditionhasattachmentrulecondition.conditiontypeolConditionHasAttachment Yes Yes Yes
用指定的重要性级别对邮件进行了标记。Message is marked with the specified level of importance. olConditionImportanceolConditionImportance Yes Yes Yes
规则只能在此计算机上运行。Rule can run only on this machine. olConditionLocalMachineOnlyolConditionLocalMachineOnly Yes Yes Yes
邮件是会议邀请或更新。Message is a meeting invitation or update. 与 olconditionmeetinginviteorupdaterulecondition.conditiontypeolConditionMeetingInviteOrUpdate Yes Yes Yes
邮件头包含textrulecondition.text中指定的单词。Message header contains words specified in TextRuleCondition.Text. textruleconditionolconditionmessageheadertextrulecondition.conditiontypeolConditionMessageHeader Yes Yes No
邮件在 "" 框中没有我的姓名。Message does not have my name in the To box. 与 olconditionnottorulecondition.conditiontypeolConditionNotTo Yes Yes No
仅将邮件发送给我。Message is sent only to me. 与 olconditiononlytomerulecondition.conditiontypeolConditionOnlyToMe Yes Yes No
邮件是外出时自动发送的邮件。Message is an out-of-office message. olConditionOOFolConditionOOF No 可访问Yes No
规则只能在特定计算机上运行,但不是当前计算机。Rule can run only on a specific machine that is not the current one. olConditionOtherMachineolConditionOtherMachine No 必需Yes Yes
文档属性恰好是或者包含或不包含指定的属性。Document property is exactly, contains, or does not contain specified properties. olConditionPropertyolConditionProperty No 必需Yes Yes
收件人地址包含textrulecondition.text中指定的词。Recipient address contains words specified in TextRuleCondition.Text. addressruleconditionolconditionrecipientaddressaddressrulecondition.conditiontypeolConditionRecipientAddress Yes Yes Yes
发件人地址包含textrulecondition.text中指定的词。Sender address contains words specified in TextRuleCondition.Text. addressruleconditionolconditionsenderaddressaddressrulecondition.conditiontypeolConditionSenderAddress Yes Yes No
发件人位于在**AddressRuleCondition** 中指定的地址列表中。Sender is in the address list specified in AddressRuleCondition.Address. olConditionSenderInAddressBookolConditionSenderInAddressBook Yes Yes No
使用指定的敏感度级别对邮件进行了标记。Message is marked with the specified level of sensitivity. olConditionSensitivityolConditionSensitivity No 必需Yes Yes
发送给收件人的**** 收件人列表 (收件人、抄送) 位于ToOrFromRuleCondition中指定的收件人列表中。Sent to recipients (To, Cc) are in the recipient list specified in ToOrFromRuleCondition.Recipients. toorfromruleconditionolconditionsenttotoorfromrulecondition.conditiontypeolConditionSentTo Yes Yes Yes
邮件大小介于 x 和 y 之间 (以 KB 为单位), 其中 x 和 y 是日期值。Message size is between x and y in units of KB, where x and y are Date values. 例如, "10; 50" 设置大小条件在10和50KB 之间。For example, "10;50" sets the size condition between 10 and 50KB. olConditionSizeRangeolConditionSizeRange No 必需Yes Yes
主题包含在textrulecondition.text中指定的词。Subject contains words specified in TextRuleCondition.Text. textruleconditionolconditionsubjecttextrulecondition.conditiontypeolConditionSubject Yes Yes Yes
我的姓名位于 "" 框中。My name is in the To box. 与 olconditiontorulecondition.conditiontypeolConditionTo Yes Yes No
邮件的 "收件人" 或 "抄送" 框中有我的姓名。Message has my name in the To or Cc box. 与 olconditiontoorccrulecondition.conditiontypeolConditionToOrCc Yes Yes No
不识别的规则条件。Unrecognized rule condition. olConditionUnknownolConditionUnknown No 可访问Yes No

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.