vba Excel VBA错误中的调试按钮在哪里
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14407061/
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
Where's the Debug button in Excel VBA error
提问by RobertFrank
Simple question I haven't been able to find the answer to with Google:
我无法通过 Google 找到答案的简单问题:
How do I get the "Debug" button to appear in the pop-up that appears when there's a run-time error in Excel 2010 VBA? I've seen it in the past, but now its missing.
如何让“调试”按钮出现在 Excel 2010 VBA 中出现运行时错误时出现的弹出窗口中?以前看过,现在不见了。
Is this a configuration issue?
这是配置问题吗?
回答by Lord Peter
If you are using On Error Goto xxx
error handling in your VBA then you won't see the Debug/Halt dialog - this is by design, because you are expected to provide your own handling routines.
如果您On Error Goto xxx
在 VBA中使用错误处理,那么您将不会看到调试/暂停对话框 - 这是设计使然,因为您需要提供自己的处理例程。
This also applies if you are using On Error Resume Next
, except that the error is completely ignored.
如果您正在使用On Error Resume Next
,这也适用,只是错误被完全忽略。
If you use the setting On Error Goto 0
, (the default setting, equivalent to not specifying either of the above settings) then you will see the Dialog box when an error occurs.
如果使用设置On Error Goto 0
,(默认设置,相当于不指定上述任何一个设置)那么出现错误时会看到对话框。
回答by Rossi
In VB Editor, Go Tools \ Options. General Tab, Error Trapping section, Then switch to Break on all Errors.
在 VB 编辑器中,转到工具 \ 选项。常规选项卡,错误捕获部分,然后切换到中断所有错误。
回答by hoooman
If you are looking to debug your code, you can do that from "Microsoft Visual Basic for Applications", you can use Alt + F11 shortcut to open it from Excel.
如果您要调试代码,可以从“Microsoft Visual Basic for Applications”进行调试,您可以使用 Alt + F11 快捷方式从 Excel 中打开它。
回答by Anonymous
You can try changing the debugging mode in the settings, that often helps. In addition, I've read reports that say that the Debug button can disappear if the VBA code is in a hosted object, so moving it to a standard module may help.
您可以尝试在设置中更改调试模式,这通常会有所帮助。此外,我读过报告说如果 VBA 代码在托管对象中,调试按钮可能会消失,因此将其移动到标准模块可能会有所帮助。
回答by mielk
It happens sometimes if you run your method directly from Immediatewindow.
如果您直接从“立即”窗口运行您的方法,有时会发生这种情况。
VBA editor, in order to display Debug option needs to break the code on some line and it is impossible when error occurs on the line in Immediatewindow.
VBA 编辑器,为了显示 Debug 选项需要在某些行上中断代码,并且在立即窗口中的行上发生错误时是不可能的。
Example:
例子:
If you run the code below directly in Immediatewindow:
如果直接在立即窗口中运行以下代码:
MsgBox 1 / 0
editor will display the following window:
编辑器将显示以下窗口:
However if you wrap this line of code into method:
但是,如果您将这行代码包装到方法中:
Sub test
MsgBox 1 / 0
End Sub
and call it from Immediatewindow like that:
并像这样从立即窗口调用它:
Call test
editor will raise an error because of the same operation but run-time error window will look like that:
由于相同的操作,编辑器将引发错误,但运行时错误窗口将如下所示: