Run Macro in another workbook already OPENED in another instance of Excel

B

benjamin.d.rogers

Hello,

I know how to open another workbook in another instance of Excel and
run a macro:

e.g.
Set xlApp = CreateObject("Excel.Application")
Set wbChart = xlApp.Workbooks.Open(filename:=ThisWorkbook.Path &
"\chart.xls")
xlApp.Run "chart.xls!mcrUpdateES", dteClose_15, dblHI_15, dblLO_15,
dblLast

But how do I do this if the workbook is ALREADY OPENED in another
instance of Excel? I think the problem centers on how to identify the
seperate instance of Excel that is already running. i.e. it's easy to
know that "xlApp" refers to the seperate instance if I'm creating that
instance at run-time, but how to refer to the seperate instance if it
was created before run-time.

Any help greatly appreciated.
Ben.
 
G

Guest

You should focus your attention on keeping everything in one instance of
Excel. Multiple instances will cause you nothing but grief because each
instance stands alone and knows nothing of the other instance... A workbook
in one instance has no (easy) way to communicate with workbooks in another
instance...
 
G

Guest

I tend to agree with Jim on this one, but I'll answer your question anyhow.
Use the GetObject function instead of CreateObject, like this:
Set xlApp = GetObject(,"Excel.Application")
 
N

NickHK

Ben,
Unless you have a good reason that requires more than one instance of Excel
use the single instance, as the other replies have suggested.
However if required, you can use GetObject to return a reference to an Excel
instance, but you cannot be sure which instance you get; it is determined by
the OS and should be considered random.

Peter T has written about this a few times
http://groups.google.co.uk/group/mi...97529?lnk=st&q=&rnum=9&hl=en#ecc950af98b97529

However, as it seems you have the Path/Filename, this should do:
http://groups.google.co.uk/group/mi...56ca8?lnk=st&q=&rnum=1&hl=en#dc9178af9fb56ca8

NickHK
 

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