【问题标题】:Error Handling - Runtime Error Box Still Occurring错误处理 - 运行时错误框仍然出现
【发布时间】:2018-05-17 15:46:23
【问题描述】:

我正在尝试在我的代码中实现一个错误处理程序,如果发生运行时错误,我已设法创建一个消息框,但在清除消息框后会弹出运行时错误框。这是我的代码的 sn-p:

combinedFilename = Application.GetOpenFilename(filter, , caption)

If combinedFilename <> "False" Then

    Set combinedWorkbook = Application.Workbooks.Open(combinedFilename)

Else

    MsgBox "No file was uploaded", vbExclamation


End If

我们将不胜感激。

非常感谢

【问题讨论】:

  • 您的 sn-p 中没有错误处理。你有任何On Error 声明吗?一个典型的例子是On Error GoTo Err,然后是一个Err: 块来处理错误本身。
  • 我没有看到任何错误处理代码?
  • 这可能不是这里的问题,但值得在 VB 编辑器中检查 >> Tools &gt;&gt; Options &gt;&gt; General tab &gt;&gt; Error Trapping 确保它没有设置为“中断所有错误”

标签: vba excel error-handling


【解决方案1】:

MsgBox之后写Err.Clear

如果清除错误。请看这个小样本:

Public Sub TestMe()

    On Error Resume Next
    Debug.Print 5 / 0           '11, because this is the number of the error.
    Debug.Print Err.Number
    Err.Clear
    Debug.Print Err.Number      '0, because the error is cleared.

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    相关资源
    最近更新 更多