vba - 错误处理程序中的错误处理

标签 vba excel error-handling

我正在使用下面的代码,当用户单击输入框中的取消按钮时,错误正在由错误处理程序处理。

但是,如果错误处理程序中再次出现错误,则错误处理程序不会处理该错误。

Sub calculateroot()

    Dim msg As String, t as Integer
    On Error GoTo myhandle
    Dim inp As Integer, sql As Single
    inp = InputBox("Enter the number to find the square root")
    sql = Sqr(inp)
    Exit Sub
myhandle:
  t = InputBox("Is this recursive ?")
End Sub

我应该在代码中进行哪些更改来处理错误处理程序中生成的错误?

最佳答案

您必须重置错误处理程序,然后设置一个新的:

Sub calculateroot()

    Dim msg As String, t As Integer
    On Error GoTo myhandle
    Dim inp As Integer, sql As Single
    inp = inputbox("Enter the number to find the square root")
    sql = Sqr(inp)
    Exit Sub
myhandle:
    On Error GoTo -1
    On Error GoTo myhandle2
    t = inputbox("Is this recursive ?")
     MsgBox t
    Exit Sub
myhandle2:
    MsgBox "myhandle2"
End Sub

关于vba - 错误处理程序中的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36839109/

相关文章:

C 检查 NULL 和错误处理

python - 如果满足条件或发生错误则执行代码

vba - Excel 用户窗体以错误的大小显示

excel - 如何使用 If-Else 语句过滤表?

excel - 为什么我不能使用 VBA 在 Excel 2013 中编辑命令栏控件?

excel - 如何在Excel单元格中添加多个链接?

android - 如何使用带有 fragment 的操作栏选项卡创建 ListView ?

loops - 运行 VBA 代码以根据特定条件删除行时出现类型不匹配错误

vba - 使用 Offset 函数复制到不同工作表的第一个空行

java - VBA/Excel 到 Java 的 dll/exe