“调试”菜单

命令 说明 工具栏按钮 键盘快捷方式
添加监视 显示“ 添加监视 ”对话框,在其中输入 监视表达式。 The expression can be any valid Basic expression. 每次进入中断模式时,监视表达式都会在“监视”窗口中更新。 “添加监视”工具栏按钮
清除所有断点 Removes all breakpoints in your project. 但是,如果已设置监视表达式或在“选项”对话框的“常规”选项卡上选择了“所有错误时中断”选项,则应用程序仍可能会中断执行。 无法撤消“ 清除所有断点” 命令。 “清除所有断点”工具栏按钮 Ctrl+Shift+F9
编译 <project> 编译项目。 “编译项目工具栏”按钮
编辑监视 显示“ 编辑监视 ”对话框,可在其中编辑或删除监视表达式。 在设置监视时可用,即使监视窗口已隐藏也是如此。 “编辑监视”工具栏按钮 Ctrl+W
运行到游标 When your application is in design mode, use Run To Cursor to select a statement further down in your code where you want execution to stop. 应用程序将从当前语句运行到所选语句,当前行的执行边距指示符 (运行到游标) 显示在 边距指示器 栏上。

例如,使用此命令可避免单步执行大型循环。
Ctrl+F8
Set Next 语句 Sets the execution point to the line of code you choose. 可以通过选择要执行的代码行并选择 Set Next Statement 命令,或者通过将 当前执行行 边距指示器拖动到要执行的代码行来设置在当前所选语句之后执行的其他代码行。

使用 Set Next 语句,可以选择位于当前所选语句之前或之后的代码行。 When you run the code, any intervening code isn't executed. Use this command when you want to rerun a statement within the current procedure or to skip over statements you don't want to execute. 不能对不同过程中的语句使用 Set Next 语句
“设置下一个语句”工具栏按钮 Ctrl+F9
Show Next 语句 Highlights the next statement to be executed. 使用 “显示下一个语句” 命令将光标放在接下来将执行的行上。 仅在中断模式中可用。 “显示下一个语句”工具栏按钮
逐语句 一次对代码执行一个语句。

在未处于设计模式中时,“逐语句”会在执行的当前行进入中断模式。 If the statement is a call to a procedure, the next statement displayed is the first statement in the procedure.

设计时,此菜单项开始执行,并将在执行第一行代码之前进入中断模式。 如果当前没有执行点,则在执行触发代码的操作(例如单击文档)之前, “单步执行” 命令可能看起来不执行任何操作。
单步执行工具栏按钮 F8
逐过程 Similar to Step Into. The difference in use occurs when the current statement contains a call to a procedure. Step Over executes the procedure as a unit, and then steps to the next statement in the current procedure. Therefore, the next statement displayed is the next statement in the current procedure regardless of whether the current statement is a call to another procedure. 仅在中断模式中可用。 单步执行工具栏按钮 SHIFT+F8
跳出 执行当前执行点所在的函数中的剩余行。 显示的下一个语句为紧跟过程调用的语句。 在当前执行点和最后执行点之间执行所有代码。 仅在中断模式中可用。 “单步执行”工具栏按钮 Ctrl+Shift+F8
切换断点 在当前行中设置或删除断点。 不能在包含不可执行代码(如注释、声明语句和空白行)的行中设置断点。

设置断点的代码行显示在“选项”对话框的“编辑器格式”选项卡上指定的颜色中。
切换断点工具栏按钮 F9

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。