Retrieve data from multiple Excel sessions

G

Guest

Is there code that I can write into my macro that allows me to access other
Excel sessions running on my computer to transfer data into a different
session that my macro is running in? My situation is described below:

There is a program on my computer (DataNav) that opens a set of experiment
data in an Excel worksheet. I am using a VBA Excel macro in a "summary" file
to grab and manipulate this data. Everything is fine if I first allow
DataNav to open the experiment data, then open my Excel macro file in the
same Excel session. However, when I download subsequent sets of experiment
data from DataNav, they each open as a new Excel session (not as a new window
in the same session). This requires me to save my macro file, close its
Excel session, and then reopen my macro in the Excel session of the new
experiment data.

Can you help?
 
P

Peter T

It's not straightforward to reference multiple Excel instances but for your
need perhaps easier than it normally is. I assume your 3rd party app creates
a new instance then loads a default / empty workbook before populating with
data. Being unsaved this will be named BookX with no extension. With API's
you can enumerate Windows finding (FindWindow32 and/or FindWindowEx or in
XL2k+ EnumWindows) each "XLMAIN" and child widows "XLDESK" > "EXCEL7" with
the caption BookX.

Then you can set a references to each BookX with GetObject("BookX").

Of course some of these BookX's may not be related to your third part app,
indeed there may one or more BookX in the same instance, though you will
already have determined which parent they belong to. However I imagine there
will be something in the Book identifies itself as relevant.

Having "got" the book your code could then quit it's parent application
having either retrieved the data or saved the BookX.

Regards,
Peter T
 

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