Is there a VBA command that causes a debug to start at that point?

excel, vba

Solution

The `Stop` command does this for you:

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

Problem

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.

Original source