How to test code? "Run" or "Debug/Step" won't work.

  • Thread starter Thread starter MyEmailList
  • Start date Start date
M

MyEmailList

I was informed that you must run code from an object or macro and the
"Run" or "Debug/Step" won't work when looking at the code development
window.

Then I was told that is not always true.

My experiments seem to indicate that

1 - code attached to "forms" will not "Run" or "Debug" from the code
development window... but must be classifed as "Functions" and run
from a macro...

2 - code a "standard module" or what ever it is called (code not
attached to a specefic form... I think) will "Run" or "Debug" from the
code development window.

I would really appriceate a few comments and clairfications on this.

thanks.

Mel
 
You can use the Debug or Immediate window to run code directly from the code
window. For a function use:

? FunctionName()

For a subroutine, enter its name:

? subroutine
 
Arvin, (or anyone else)

I guess I'm doing something wrong.

Looking at the Windown into which you see and enter the code... I've
clicked "Run" and it ask me for a "Macro" name...

I tried typing in subroutine and function names as you suggested with
the leading "?" No joy.

then I tried typing into the "immideate" window... no joy.

Here is my "function"

Public Function TestCode()
MsgBox "Function Worked"
End Function

Here is my Subroutine

Public Sub SayWhat()
MsgBox "Say What!?"
End Function

So... entering
? TestCode() 'doesn't work
? SayWhat 'doesn't work

What am I doing wrong?

This is code attached to a "Form" ... should that matter? Should it
only be code in the "Standard Module" that is not attached to a
particular form?

thanks

Mel
 
Yes, it does matter that your code is not in a standard module.

Either move it into a standard module, or use the module name.

For example, if the code is in the module of Form1, use:
? Form_Form1.TestCode()
 
In addition to Allen's remarks, have a look at the SayWhat sub. You are
ending it as a function and it won't compile that way.
 
Back
Top