问题
I am trying to write a simple macro to add 1 to the cell's current value:
Sub add()
MsgBox Selection.Value
Selection.Value = Selection.Value + 1
End Sub
I receive the following error message when I click a (numeric) cell and try to run the macro:
Cannot Execute in Break Mode
What am I missing?
回答1:
You are already executing a macro and somehow stopped its execution (e.g. due to an unhandled error or because you pressed Ctrl-Break during the execution). In this state, you cannot execute another macro.
In the Visual Basic Editor, you need to press the Stop button:

Then you can run the macro.
If you want to understand where the current execution is stopped, right click the code and select Show Next Statement. If you then press F8 you can step through the code. F5 continues the execution.
回答2:
And you should check if the value in the cell is numeric. Example
Sub add()
If IsNumeric(Selection.Value) Then
Selection.Value = Selection.Value + 1
Else
MsgBox ("Not a value selected")
End If
End Sub
回答3:
Sub Lower()
Range ("e3"), Value = Range("e3"), Value - 1
End Sub
Sub Higher()
Range ("e3"), Value = Range("e3"), Value + 1
End Sub
来源:https://stackoverflow.com/questions/14934433/cannot-execute-macro-in-break-mode