Partager via


Rule.Execute Method (Outlook)

Applies a rule as an one-off operation.

Version Information

Version Added: Outlook 2007

Syntax

expression .Execute(ShowProgress, Folder, IncludeSubfolders, RuleExecuteOption)

expression A variable that represents a Rule object.

Parameters

Name

Required/Optional

Data Type

Description

ShowProgress

Optional

Boolean

True to display the progress dialog box when the rule is executed, False to run the rule without displaying the dialog box.

Folder

Optional

Folder

Represents the folder where the rule will be applied.

IncludeSubfolders

Optional

Boolean

True to apply the rule to subfolders of the folder indicated by the Folder parameter; False to apply the rule only to that folder but not its subfolders.

RuleExecuteOption

Optional

OlRuleExecuteOption

Represents whether to apply the rule to read, unread, or all messages in the folder or folders specified by the Folder and IncludeSubfolders parameters.

Remarks

Use Rule.Execute to apply a rule as a one-off operation regardless of whether Rule.Enabled is True. Use Rule.Enabled and then Rules.Save if you want to apply the rule consistently and persist the rules beyond the current session.

The parameters to the Execute method are optional. If you do not specify any parameters, the rule will be applied to all messages in the Inbox but not to the subfolders of the Inbox. The default values for the optional arguments are as follows:

Parameter

Default Value

ShowProgress

False

Folder

Inbox

IncludeSubfolders

False

RuleExecuteOption

OlRuleExecuteOption.olRuleExecuteAllMessages

If ShowProgress is True and the user cancels the progress dialog box, rule execution is canceled in the same manner as if the user had canceled rule execution through the Rules and Alerts Wizard. Execute returns an error when the user cancels the progress dialog.

If you plan to show a custom progress user interface instead of using the progress dialog box, you should be aware that there are no events that indicate when rule execution starts and stops.

See Also

Concepts

Rule Object Members

Rule Object