如何在停止VBA错误时允许内置Excel错误?
我有一个excel文件的结帐VBA代码。如果该文件无法签出,我希望excel能够做到这一点通常的错误:当我可以使用此文件时通知我'但是--NOT - (此时它确实)在此之后有一个VBA错误。
但是,如果我使用On Error Resume Next / On Error Goto,它会停止VBA错误(好),但也会禁用excel'通知我'消息(不好)。
有什么想法吗?
代码:
Sub CheckOut()
' Determine if workbook can be checked out.
rspn1 = MsgBox("Do you want ot begin the survey?", vbYesNo)
If rspn1 = vbNo Then GoTo No Else GoTo Yes
Yes:
Dim x As String
x = Application.ThisWorkbook.FullName
Workbooks.CheckOut x
On Error GoTo 2:
MsgBox ("The file is now checked out to you. You will be prompted to check in again when finished."), vbOKOnly, "Check Out Complete"
2:
Exit Sub
No:
ThisWorkbook.Close
End Sub