是否有 VBA 命令导致调试在该点开始?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14977377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:42:27  来源:igfitidea点击:

Is there a VBA command that causes a debug to start at that point?

excelvbaexcel-vba

提问by Robert

The context of this question is that I am using message boxes as a tool to help me get familiar with a quite large amount of VBA macros that are running on a collection of Excel workbooks.

这个问题的上下文是我使用消息框作为工具来帮助我熟悉在 Excel 工作簿集合上运行的大量 VBA 宏。

I am carefully inserting message boxes within the code which pop up and tell/remind me where we are in the code. I would like to have a button in these boxes which will take me into a debug of the code at that point.

我小心地在代码中插入消息框,这些消息框会弹出并告诉/提醒我我们在代码中的位置。我想在这些框中有一个按钮,届时我将进入代码调试阶段。

At the moment my solution is to perform a division-by-zero if the `Yes' button is chosen. Here is an example snippet:

目前我的解决方案是如果选择“是”按钮,则执行除以零。这是一个示例片段:

Dim MyError as Double
...
If MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes Then MyError = 1# / 0

It works, but is not very elegant.

它有效,但不是很优雅。

I was hoping there is a command which will start the VBA debug mode at the point that command is called.

我希望有一个命令可以在调用该命令时启动 VBA 调试模式。

采纳答案by Peter Albert

The Stopcommand does this for you:

Stop命令为您执行此操作:

If MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes Then Stop

回答by Dirk Vollmar

Yes, there is:

就在这里:

Debug.Assert False