Not able to "Step in" - Debug

H

Hari

Hi,

I have a Sub Workbook_BeforeSave. (This sub further calls another Function)

The file doesnt save if there are any inconsistency within the file's data
and flags the errors with a yellow fill color.

I have inputted correct data but the file is not saving and giving a message
that one particular cell has incorrect data and has filled it with yellow
color.

Now, I want to run this sub by stepping in to it ( step by step with F8 )so
that I get a better understanding of why it is happening.

But in VB when I choose Workbook_beforesave and press F8, nothing happens.

Where am I going wrong ?

Regards,
Hari
India
 
J

JE McGimpsey

You can't start a sub with an argument using F8.

However, if you set a breakpoint at the first statement in the macro and
choose Save from the workbook, you'll be dumped into the VBE and you can
step with F8.
 
T

TroyW

Hari,

Another method is to insert the command "Stop" in the code. When the
program encounters the Stop command it will halt execution and place you
into debug mode waiting for you to use F8 to continue executing the program
line-by-line. Of course, you would want to remove "Stop" from your code
after you're done debugging.

You can also do fancy things like using a variable to turn on and off the
debug code. You can declare a Public Boolean variable that turns on and off
all of your lines of debug code. In the example below, I've created a
boolean named: PbDebugOn

At the beginning of the code you would set the variable True.
PbDebugOn = True

Then lines like the one below would evaluate True and stop your code in
debug mode.
If PbDebugOn = True and iCount > 100 then Stop

Troy


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Stop '''Code will stop and wait.
'''The rest of your code below.

End Sub
 
H

Hari

Hi Troy and JE M

Thanx a lot for ur help. Im able to pin down the error.

Regards,
Hari
India
 

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