Slowing down code execution

U

ubu

How do I slow down the execution of code in VBA without
having to press F8 each time? I want to view the code
execute slowly. Is there a timer command I can use to do
this?
 
K

Klaus Linke

ubu said:
How do I slow down the execution of code in VBA
without having to press F8 each time? I want to view
the code execute slowly. Is there a timer command I
can use to do this?


Hi ubu,

As Martinique said, not quite as you want.
Some alternatives:

If you keep F8 pressed, the code will be stepped through rather fast.

You could set a couple of breakpoints on lines where you want to see what's
happening.
You can do that by clicking to the left of the line, or with F9; a red
bullet should appear.

Then use F5 to run the code up to the next breakpoint.

You can put the cursor in some line, and use Ctrl+F8 to run all the lines
up to that point.

If you have subroutines or functions that you don't want to step through,
you can use Shift+F8.

If you are interested in some variable, you can add a "watch" for it, and
make the code stop for example each time after the variable changes
(right-click on it somewhere in the code and choose "Add watch...", and in
the dialog check the corresponding check box).

Or you could create a dummy Boolean variable, and make the code stop when
the variable is "True".
You could use that for example to make the code stop when the Selection is
collapsed:

Dim boolDebug as Boolean
' ...
boolDebug=(Selection.End=Selection.Start)

Then add a watch for boolDebug that stops the code when boolDebug is
"True".


Greetings,
Klaus
 
K

Klaus Linke

You could slow down the speed by which the code is single-stepped when you
hold down the F8 key:
Change the typomatic rate in the Windows Control Panel > Keyboard
temporarily.

One other method that can avoid single-stepping altogether is to write
stuff you are interested in to the immediate window with "Debug.Print"
(say, the value of a variable at a certain line in the code). After you
have run the macro, you can look at the immediate window to check if the
output corresponds to your expectations.

Klaus
 
U

ubu

Thanks for the response. I was aware of the various
debugging techniques.

What I have is a timing issue and if I could slow down the
execution I could see exactly how the code executes on my
Word document.

I'm using Automation from Access and it's a bit tricky
debug when you have two applications running.
 
H

Helmut Weber

Hi ubu * (what),
depending on how complex and how long and so on
your code is, would a small routine like
wait(seconds or milliseconds) between
the appropriate lines help? If so, let us know.
You could even introduce a variable at the start
of your code that would allow to slow down execution
in differrent steps or to switch it off.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Mike,
.... but only in case ubu * doesn't want to
let his or her computer to do something else
in the meantime...
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 

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