Call subs from another wkbk?

H

Huyeote

Hi call,

Any guru can tell me if I can call a sub in one workbook from anothe
workbook? If so, how?

Many thanks.

Huyeot
 
A

agarwaldvk

As suggested by John Walkenbach in his book, there are 2 option
available to you :-

1. use the run method of the application object like so :-
application.run "full path name including the book name and the su
procedure name that you are trying to execute - all in double quote
with the book name in single quotes within the double quotes" as show
below :-

application.run "'c:\myfolder\myfile.xls'!myMacro"

This does not require for you to establish a reference to the referre
workbook.


2. Establish a reference to the desired workbook usin
Tools|References| and then browsing to find the desired workbook. Th
referred workbook doesn't need to be open for you to be able to use
sub in that workbook. Once the reference has been established say to
procedure called "myMacro", you can call the same by the followin
statement :-

call myMacro or simply
myMacro


Hope this helps!



Best regards




Deepak Agarwa
 
F

ForSale

I know that i am not the one that posted the question, but i too wante
something similar. i tried both options and they both opened the fil
that contained the macro that was supposed to be run. is it possibl
to run a macro without opening the containing workbook
 
M

Myrna Larson

What is your ultimate goal? That the user doesn't see the new workbook on the
screen? If so, turn of screenupdating.
 
T

Tom Ogilvy

the short answer is no. The workbook has to be open to run the macro.
Myrna offers a workaround for not making it obvious that it is open.
 
Top