The context of this question is that I am using message boxes as a tool to help me get familiar with a quite large amount of VBA macros that are running on a collection of Excel workbooks.
I am carefully inserting message boxes within the code which pop up and tell/remind me where we are in the code. I would like to have a button in these boxes which will take me into a debug of the code at that point.
At the moment my solution is to perform a division-by-zero if the `Yes' button is chosen. Here is an example snippet:
Dim MyError as Double
...
If MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes Then MyError = 1# / 0
It works, but is not very elegant.
I was hoping there is a command which will start the VBA debug mode at the point that command is called.
One of the methods used to debug VBA code is by running the code. The shortcut key for the command is F5. Start by placing the cursor into the UserForm or Sub (macro) and then press F5 to run the sub. Please note that F5 will not work when running a sub that requires parameters to execute a function.
F8 Key Stops Working. When debugging Excel VBA code, you can use the F8 key, or the Step Into command, to step through the code, one line at a time.
The best way to debug a user defined function (UDF) is by writing a temporary Sub procedure that calls your function and then step into the Sub procedure by pressing F8 key.
The Stop
command does this for you:
If MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes Then Stop
Yes, there is:
Debug.Assert False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With