Switching between Excel Applications

  • Thread starter Thread starter silks
  • Start date Start date
S

silks

Hiya all,

I'm quite new at all this programming stuff and need some help.

I have a visual basic 6 exe which creates a new excel file and open
it, and opens an existing excel file. This means I have 2 occurences o
Excel running.

It then runs a macro in the existing Excel file.

What I need to know is how do I use my macro to switch between the
occurences of Excel. I know how to switch when everything is in the on
application but this is completely ruining my day!

Cheers
 
Sounds like you would prefer to have just one instance of Excel running
instead of 2.

To do this, before you create a new instance of excel, test to see
whether there is an instance already running using:

*******************************************
dim myXL as excel.application
on error resume next
set MyXL = Getobject(, "Excel.Application")

'test for error
'if error then excel is not open so create new instance
if err <> 0 then
set MyXL = new excel.application
end if

on error goto ProcError
*********************************************
Dom
 
Thanks, that work's a treat (especially since the way my code is writte
I don't need the test).

Cheers
 

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