gpt4 book ai didi

excel - 如何阻止excel运行所有错误

转载 作者:行者123 更新时间:2023-12-03 08:24:47 25 4
gpt4 key购买 nike

我有以下代码来处理我的错误:

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被触发时,它是唯一的一个,因此它从发现的错误开始从上到下运行。

我的问题是:如何更改此代码,使其仅引发错误之一?

在此先感谢您的帮助。

最佳答案

尝试在消息框后添加一行Exit Sub。错误1的消息框后继续执行。

所以它应该看起来像这样:

Exit Sub

error1
MsgBox "Claims followup.xlsm is not open." & Chr(10) & Chr(10) & "Open the file in read/write"
Exit Sub
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."
Exit Sub
error3
MsgBox "Your Claim followup file is in -read only- mode. Your changes may not be saved"
Exit Sub
End Sub

关于excel - 如何阻止excel运行所有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44799448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com