Call subs from another wkbk?

  • Thread starter Thread starter Huyeote
  • Start date Start date
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
 
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
 
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
 
What is your ultimate goal? That the user doesn't see the new workbook on the
screen? If so, turn of screenupdating.
 
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.
 

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

Back
Top