【发布时间】:2017-06-28 10:04:07
【问题描述】:
我有以下代码来处理我的错误:
Sub some_sub()
On Error GoTo error1
Some code here
On Error GoTo error2
Some more code here
On Error GoTo error3
final piece of code here
Exit Sub
error1
MsgBox "Claims followup.xlsm is not open." & Chr(10) & Chr(10) & "Open the file in read/write"
error2
MsgBox "Please make sure that the Claims followup file is open." & Chr(10) & Chr(10) & "If the file is open make sure that you the Solicitation Number is written correctly."
error3
MsgBox "Your Claim followup file is in -read only- mode. Your changes may not be saved"
End Sub
Sub some_sub()
On Error GoTo error1
Some code here
On Error GoTo error2
Some more code here
On Error GoTo error3
final piece of code here
Exit Sub
error1
MsgBox "Claims followup.xlsm is not open." & Chr(10) & Chr(10) & "Open the file in read/write"
error2
MsgBox "Please make sure that the Claims followup file is open." & Chr(10) & Chr(10) & "If the file is open make sure that you the Solicitation Number is written correctly."
error3
MsgBox "Your Claim followup file is in -read only- mode. Your changes may not be saved"
End Sub
但是,当检测到“error1”时,它也会触发“error2”和“error3”,但我只希望它触发“error1”。如果“error2”触发“error3”也会触发。而当error3被触发时,它是唯一的,所以它从发现的错误开始从上到下运行。
我的问题是:如何更改此代码,使其仅触发错误之一?
提前感谢您的帮助。
【问题讨论】:
标签: excel error-handling vba