Ignore breakpoint when running a macro

H

hmm

When troubleshooting a macro, there are instances where I want to switch back
and forth between running and debugging. There are breakpoints in my
debugging, which I find I must remove before running to prevent interruption
in execution. Then, when I go back to debugging I need to reinsert them.

How can I tell Excel to ignore breakpoints when running (without deleting
them, so that I may use the same breakpoints for future debugging)?

Thanks.
 
J

John Bundy

I don't think such a thing is possible, what i do is where my breakpoints
are, i go to Edit->Bookmarks and toggle bookmark, this will create a mark by
that line of code, put those on your breaks and run, then you can go to next
or previous bookmarks and put breaks on the ones you want. If you right click
and customize your toolbar, you can put them right on your toolbar and its
very easy.
 
B

Bob Phillips

Use conditional compilation.

Add a constant declaration at the start of the module like

#Const InDebug = True

Then in your code add statements like

#If InDebug Then
Stop
#End If

your code will stop at those points. When you want to stop debugging, just
change the True to False.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
H

Helmut Weber

Hmm,

don't worry about this being Word code.

Sub Test9987()
Dim Mystop As Boolean '!
Mystop = False ' disable breaks
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=1
If Mystop Then Stop '!
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=3
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

hmm

Not sure, Helmut, I understand what the code does, or how to implement it.
Can you explain it? Thanks.
 
H

Helmut Weber

Hi hmm,
Not sure, Helmut, I understand what the code does, or how to implement it.
Can you explain it? Thanks.

That was probably too simple.
I define a boolean variable "myStop".
If I want the code to stop,
I set "myStop" to true, like

Sub Test9987()
Dim Mystop As Boolean '!
Mystop = True
' your Excel code goes in here
if myStop then stop
' more Excel code goes in here
if myStop then stop
' more Excel code goes in here
End sub

If myStop is true then the sub stops
at every line "if myStop then stop"

If myStop is false, which is the default value,
then the code doesn't stop at all.

You may even define different boolean variables
or an array of booleans, in order to stop only
at certain lines, like:

Sub Test9987A()
Dim Mystop1 As Boolean '!
Dim Mystop2 As Boolean '!
Mystop1 = True
' your Excel code goes in here
if myStop1 then stop
' more Excel code goes in here
if myStop2 then stop
' more Excel code goes in here
End sub

which will stop only at "if myStop1 then stop"

HTH

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top