我使用的 VBA 程序具有错误处理功能。当最终用户向我提及错误时,程序的焦点通常会放在调试模式下的错误处理程序上。在这些情况下,我想调查错误发生的原因,因此我输入“resume”并运行“resume”代码行。是否有允许我恢复程序的快捷键、按钮或菜单选项?如果我尝试在“立即”窗格中使用“resume”,则会收到错误消息。
答案1
看起来你想要这样的东西。
Private Sub ErrorHandlerDeveloper_Test()
Dim uErrorMsg As String
Dim devStatus As Boolean
devStatus = True ' Change to false when shared
'devStatus = False
Dim procName As String
procName = "ErrorHandlerDeveloper_Test"
On Error GoTo ErrorHandler
' *********************************
' code that triggers an error here
err.Raise 11
' *********************************
ExitRoutine:
Exit Sub
ErrorHandler:
If devStatus = True Then
err.Clear
On Error GoTo 0
' Return to the error line and highlight
Resume
Else
uErrorMsg = "Take note of this information and advise the developer." & vbCr & vbCr
'uErrorMsg = uErrorMsg & "Error Source...: " & Err.Source & vbCr & vbCr
uErrorMsg = uErrorMsg & "Procedure......: " & procName & vbCr & vbCr
uErrorMsg = uErrorMsg & "Error Number..: " & err.Number & vbCr & vbCr
uErrorMsg = uErrorMsg & "Description.....: " & err.Description
Debug.Print uErrorMsg
MsgBox uErrorMsg, , "Generated in " & procName
Resume ExitRoutine
End If
End Sub