Switching Between Excel Instances

  • Thread starter Thread starter SeanEvans
  • Start date Start date
S

SeanEvans

I am trying to switch between two different instances of excel (the
show up as seperate spreadsheets on the taskbar) but the code I hav
been given to try doesn't work -

Dim OtherSheet As Object ' Variable to hold reference

On Error Resume Next
Set OtherSheet = GetObject(, "Excel.Application")
Set OtherSheet = GetObject("U:\Decision Support\VB Testing\Fil
swap2.xls").Activate ' <<<< FULL FILE PATH HERE
OtherSheet.Application.Visible = True
Set OtherSheet = Nothing ' Release reference to the application an
spreadsheet

It just throws up an error 424 Object Required at the second get objec
line. Can anyone point me in the right direction
 
I don't think it is possible to select one of several instances of Excel
using GetObject (or anything else). GetObject acquires the latest instance or
nothing if Excel is not running.

Why don't you start your own instance of Excel:

Set xl = CreateObject("Excel.Application")

Then open each of your workbooks:

cl.workbooks.Open "your fully qualified file name" ' repeat for your workbooks

Then, you can refer to any workbook

xl.Workbooks("name of wb").etc.etc

PS: Before you open a workbook, you need to ensure that it is not already
open. The simplest way is to use error trappng around the Workbooks.Open code
else use the _lopen & _lclose APIs.
 

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