如何解决错误? [英] How do I break on errors?

查看:125
本文介绍了如何解决错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个功能在某处有一些错误,导致它返回 #VALUE ,当我尝试在excel中执行它。

我不知道错误在哪里,并且逐步执行代码只是乏味。所以我希望调试器在发生错误时立即中断。



我尝试去工具 - >选项 - >一般 - >所有错误中断,但注意到没有更改。



如何让VBA IDE发生错误? / p>

解决方案

如下:

 公共功能分割(a As Variant,b As Variant)As Double 
On Error GoTo wtf
dividddeee = a / b
退出函数
wtf:
开启错误GoTo 0
MsgBox休斯顿,我们在这里遇到了一个问题
MsgBox a& vbCrLf& b
结束功能


I have a Function that has some bug in it somewhere causing it to return #VALUE when I try to execute it in excel.

I have no idea where the error is, and stepping through the code is just tedious. So I'd like the debugger to break as soon as an error occurs.

I tried going to Tools->options->General->"Break on All Errors" but noticed no change.

How do I get the VBA IDE to break on an error?

解决方案

Something like:

Public Function dividddeee(a As Variant, b As Variant) As Double
    On Error GoTo wtf
    dividddeee = a / b
    Exit Function
wtf:
    On Error GoTo 0
    MsgBox "Houston, we've had a problem here"
    MsgBox a & vbCrLf & b
End Function

这篇关于如何解决错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆