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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:09:27  来源:igfitidea点击:

On Error Goto 0 not resetting error trapping

excelexcel-vbaerror-handlingvba

提问by whytheq

I was under the impression that On Error GoTo 0reset error handling.

我的印象是On Error GoTo 0重置错误处理。

So why does On error resume nextnot 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 -1orErr.Clearto reset error trapping.

您需要使用On Error GoTo -1Err.Clear重置错误捕获。

Check this answerI posted a few months ago for a more detailed explanation.

检查我几个月前发布的这个答案以获得更详细的解释。