8

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.

2 Answers 2

10

The Stop command does this for you:

If MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes Then Stop
9

Yes, there is:

Debug.Assert False
1
  • so you could also use: Debug.Assert (MsgBox("Just entered function XYZ(). Want to debug?", vbYesNo + vbDefaultButton2) = vbYes)
    – gicalle
    Commented Sep 10, 2014 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.