Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoking and debugging VBA From Excel

Status
Not open for further replies.

gharabed

Programmer
Sep 7, 2001
251
US
I feel completely stupid asking this but I have inherited an excel spreadsheet with some VBA code in it that produces a report. I want to invoke the VBA sub that is defined in the spreadsheet but I'm not sure how to do it. Is it possible to invoke it from the "immediate" box? I also want to set a break point and step through the code to see where the problem I am encountering arises. What is the easiest way to do this? Is there a way to invoke the sub from a macro? Thanks! -Greg-
 


Hi,

What do you mean by "invoke?" Run? Edit? Debug?

Have you looked at Tools/Macro....

BTW, macro and VBA are used interchangeably, but in reality a MACRO is not VBA code.

ctl+F11 - creates a new MACRO sheet
alt+F11 - toggles between the VBA Editor and the active sheet.

Skip,

[glasses] [red]Be Advised![/red] The only distinction between a bird with one wing and a bird with two, is merely...
a difference of A Pinion! [tongue]
 
I want to run the vba sub but I want to run it in debug mode so I can step through the code.
 


In the VBA Editor, Debug Toolbar, select Step into F8.

Skip,

[glasses] [red]Be Advised![/red] The only distinction between a bird with one wing and a bird with two, is merely...
a difference of A Pinion! [tongue]
 
And have a look at the STOP instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So you are saying I can just run the VBA sub directly? When I do a "Step Into" nothing happens. How do you select the sub you want to debug and how do you set up the input parameters?
 
In the debug window (Ctrl+G) either:
nameofsub valueofarg1, valueofarg2

or:
call nameofsub(valueofarg1, valueofarg2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The way I do it is just to click in the sub you want to run and then run line by line using F8

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
I actually figured it out. All I need to do is set a break point in the code where I want it to break. Then from the "immediate" window enter the call to the function. The trick was in dealing with the object model. If I just called the sub directly I got errors. I needed to prefix the VBA sub in the call with the proper context. In this case it was

call thisWorkbook.<subname>
 
Hi there,

I'm not sure how you have your Project structured. If the procedure is declared as Public and is in a standard Module you can call from anywhere within the Project. If you have it declared as Private or is not in a standard Module, the technique may be different. It all depends on your structure.

NB: Putting a breakpoint (keyboard shortcut F9) and using the line command Stop are synonymous.

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top