Private change_ind As Integer
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
change_ind = 1
End sub
Private Sub CommandButton1_Click()
If change_ind = 1 Then
MsgBox "Update has occurred"
Else
MsgBox "No updates"
End If
End Sub
Sub mySub()
On Error GoTo CatchError 'I called it CatchError but you can call it whatever
'--All of your code here including "If MsgBox("File has been updated", vbinformatoin) = ok Then Exit Sub"
CatchError:
'Here put what you want to do in case of an error, for example
'MsgBox "The code stopped because of an error"
End Sub
2 回答
我不确定这是否完全回答了你的问题,但你可以试试这个:
(NB.Substitute相关代码代替消息框)
你需要的是一个错误处理程序 . 您需要在sub的开头设置“On Error”语句,然后编写错误处理程序 .
这是一个资源,您可以在其中找到有关如何设置的信息:https://support.microsoft.com/en-us/kb/141571#/en-us/kb/141571
你的代码就像这样