On Error Goto 0不重置错误捕获 [英] On Error Goto 0 not resetting error trapping
本文介绍了On Error Goto 0不重置错误捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的印象是 On Error GoTo 0
重置错误处理。
所以为什么下一个错误恢复
似乎没有在以下注册?
Sub GetAction()
Dim WB As Workbook
设置WB = ThisWorkbook
错误GoTo endbit
'引发错误
Err.Raise 69
退出子
endbit:
错误GoTo 0'<<<重设错误处理?
关于错误简历Next
WB.Sheets(x)。列(D:T)。AutoFit
MsgBox忽略错误成功并继续下一步
End Sub
解决方案
使用错误GoTo -1
或 Err.Clear
重置错误陷阱。 p>
检查这个答案我在几个月前发布了一个更详细的解释。
I was under the impression that On Error GoTo 0
reset error handling.
So why does On error resume next
not seem to be registering in the following?
Sub GetAction()
Dim WB As Workbook
Set WB = ThisWorkbook
On Error GoTo endbit:
'raise an error
Err.Raise 69
Exit Sub
endbit:
On Error GoTo 0 '<<<reset error handling?
On Error Resume Next
WB.Sheets("x").Columns("D:T").AutoFit
MsgBox "ignored error successfully and resumed next"
End Sub
解决方案
You need to use On Error GoTo -1
or Err.Clear
to reset error trapping.
Check this answer I posted a few months ago for a more detailed explanation.
这篇关于On Error Goto 0不重置错误捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文