vba On Error Goto 0 不重置错误捕获
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15542747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
On Error Goto 0 not resetting error trapping
提问by whytheq
I was under the impression that On Error GoTo 0
reset error handling.
我的印象是On Error GoTo 0
重置错误处理。
So why does On error resume next
not seem to be registering in the following?
那么为什么On error resume next
在下面似乎没有注册呢?
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
采纳答案by Francis Dean
You need to use On Error GoTo -1
orErr.Clear
to reset error trapping.
您需要使用On Error GoTo -1
或Err.Clear
重置错误捕获。
Check this answerI posted a few months ago for a more detailed explanation.
检查我几个月前发布的这个答案以获得更详细的解释。