Can a macro call a Sub?

G

Guest

I know that by using the RunCode action of a macro you can call a Function,
but is there any way to call a Sub directly?

If I understand correctly, the main difference between subs and functions is
that a function is used to return a value whereas a sub cannot.

I have procedures defined as Subs (because they don't return values) that I
call from within other form modules and I want to call them from a Macro as
well. Is the only way to do this to redefine them as Functions w/o a return
value?
 
D

Douglas J. Steele

Yes, you need to change them to functions (or else create functions that
call them)
 
M

Marshall Barton

Sasquatch said:
I know that by using the RunCode action of a macro you can call a Function,
but is there any way to call a Sub directly?

If I understand correctly, the main difference between subs and functions is
that a function is used to return a value whereas a sub cannot.

I have procedures defined as Subs (because they don't return values) that I
call from within other form modules and I want to call them from a Macro as
well. Is the only way to do this to redefine them as Functions w/o a return
value?


Either that or create a one line function that calls the
sub. I guess this is another reason why macros are not a
very good implementation tool.

Note that you do not need to use a function's return value.
I.e. you can call a function using the same syntax that you
use to call a sub.
 
G

Guest

One note of warning - if you call a function from a macro you have specify
'()' after the function name for some stupid reason. So if your function is
called Function1 then for the function name you have to put Function1(),
otherwise you'll get an error.
 

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