How to run a function or procedure in Immediate Pane

G

Guest

Hello everyone,
I have a function:

Public Function myprint()
Debug.Print "hello, hello"
End Function

When I enter "?myprint()" in the Immediate Pane, I got an error message
saying:"Expecting varialbe or procedure, not module". If I enter

Debug.Print "hello, hello"

in the Immediate Pane and press enter key, I will get "hello, hello", the
result of the debug.pring, which is what I want. But I would like to run the
function or procedure because I have program that has more code and I want to
trace the result of each line.

Any idea? What did I do wrong?

Thanks.
 
A

Allen Browne

Sounds like a naming clash.

Try renaming the module to something like Module1.
It cannot have the same name as your procedure.
 
A

Alex Dybenko

Hmm,
maybe you have a module also called "myprint"? then you have to rename
either module or function
 
G

Guest

Well I changed the function to a procedure:

Public Sub myprint()
Debug.Print "hello, hello"
End Sub

When I ran "?myprint()" in the Immediate page, I got the same error message.
 
G

Guest

Thanks. I did find a module with same name. I deleted it. Now when I run
"myprint" in the immediate pane:

?myprint

I did not get any error. I did not get the debug.print line"hello, hello"
either. If I enter

?myprint()

I got an error message saying "Run time error 9, Script out of range."

Any suggestions?

Thanks.
 
J

John Spencer (MVP)

Try just
MyPrint

Your Sub doesn't return any value
A function could return a value and print that

Function myPrint()
debug.print "Hello"
MyPrint = "Return this string"
end Function

So
?MyPrint()
would print
"Hello"
and The ? (shorthand for Print) would see "Return This string" and print that to
the immediate window.
 

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