Add a watch expression

A watch expression is an expression that you define to be monitored in the Watch window. When your application enters break mode, the watch expressions you selected appear in the Watch window where you can observe their values.

To add a watch expression

  1. On the Debug menu, choose Add Watch. The Add Watch dialog box is displayed.

  2. If an expression is already selected in the Code window, it is automatically displayed in the Expression box. If no expression is displayed, enter the expression you want to evaluate. The expression can be a variable, a property, a function call, or any other valid expression.

  3. Select a module or procedure context in the Context group to select the range for which the expression will be evaluated.

    Note

    Select the narrowest scope that fits your needs. Selecting all procedures or all modules can slow down module execution considerably, because the expression is evaluated after execution of each statement. If you select a specific procedure for a context, execution is affected only while the procedure is in the list of active procedure calls. Choose Call Stack from the View menu to display the list of active procedures.

  4. Select an option in the Watch Type group to define how the system responds to the watch expression.

    • To display the value of the watch expression, choose Watch Expression.

    • To stop execution if the expression evaluates to True, choose Break When Value is True.

    • To stop execution when the value of the expression changes, choose Break When Value Changes.

  5. Choose OK.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.