Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set breakpoint in VBA code programmatically

I have a very large piece of code written in VBA (>50,000 lines - numerous modules). There is one array of interest to me, and I'd like to find all the conditions under which the value of any element of this array changes. The values can change in any module. Running the script line by line is not the most efficient option due to the size of the code.

I am looking for better ways to solve this problem. Two ways that come to my mind is to programmatically set a breakpoint (which I am not sure if can be done) or programmatically insert an if-block after each assignment that somehow alerts me that the value has changed. (not preferred).

So my question boils down to:

  1. Is it possible to programmatically set breakpoints in VBA code?
  2. If the answer to the above question is No, what is an efficient way to solve this problem?

UPDATE: Thanks for the comments/replies. As I had implied, I am interested in the least amount of modification to the current code (i.e. inserting if-blocks, etc) and most interested in the break-point idea. I'd like to know if it's doable.

like image 859
SMir Avatar asked Jul 24 '12 16:07

SMir


People also ask

How do I add a stop in VBA?

Setting and Removing BreakpointsClick in the grey margin to the left of a line of code to set (or remove) a breakpoint for it. Alternatively, press F9 to toggle a breakpoint on or off. A surprisingly useful short-cut key is SHIFT + CTRL + F9, which removes all of the breakpoints that you've set.

How do I insert a breakpoint in Excel?

The quickest way to do this is by pressing Alt + F11 while your Excel database file is open. To set a breakpoint, find the line of code where you'd like to suspend your program. Left-click in the grey bar to the left of the code. A red dot should appear and the line of code should be highlighted in red.


2 Answers

There are Two Ways to do that:

  1. Use Stop Key word. Example as given below, set a break point at Stop

     if (x = 21 ) Then
       Stop
      End If
    
  2. Using Add Watch enter image description here

    Go to Debug -> Select Add Watch

    Go to Debug -> Select Add Watch

like image 29
Arpan Saini Avatar answered Oct 13 '22 11:10

Arpan Saini


Use the keyword STOP to break te code if a certain condition is true.

like image 102
html_programmer Avatar answered Oct 13 '22 10:10

html_programmer