Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Get Workbook path but from another excel instance

I open a rating workbook which, when a userform button is pressed,
opens another instance of excel and runs multiple workbooks that do
many calculations. When this is completed, i want the next part of the
rating code to remember the path for one of the two workbooks that are
left open in the other instance of excel.

When i try looking through the available workbooks, i get:
personal.xls
Book1.xls
rating.xls

These are the workbooks that are open in the 1st instance of excel.
How do i look at the workbooks in the 2nd instance.?
property listing.xls
summary.xls

I thought this code might do it, but just keeps looping through the
1st instance, without moving to the 2nd.
Code:
Do
Set XLAPP = GetObject(, "Excel.Application")
If Not XLAPP Is Nothing Then
For Each wkbk In XLAPP.Workbooks
If wkbk.Name = "Property Listing - " &
UserForm2.ComboBox1.Value & ".xls" Then
wkbk.Saved = True
x = wkbk.Path
wkbk.Close
End If
Next wkbk
End If
Loop


So what i want to do is:
open my rating workbook
press the userform button
have a 2nd instance of excel open
have multiple workbooks open to do calculations, leaving only 2
workbooks remaining

so far so good

have x = the path of the propertylisting workbook

x is in the code of the rating workbook userform and i can't get to
read the workbooks that are in the other instance of excel.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Get Workbook path but from another excel instance

Hi

Set XLAPP = GetObject(, "Excel.Application")

will return the existing object if one already exists.

You probably want
Set XLAPP = GetObject("", "Excel.Application")

which will return a second object (see the Help for GetObject).

Better still do this in your case:
Dim XLAPP as Excel.Application
Set XLAPP = New Excel.Application

regards
Paul



On Mar 16, 12:08 pm, wrote:
I open a rating workbook which, when a userform button is pressed,
opens another instance of excel and runs multiple workbooks that do
many calculations. When this is completed, i want the next part of the
rating code to remember the path for one of the two workbooks that are
left open in the other instance of excel.

When i try looking through the available workbooks, i get:
personal.xls
Book1.xls
rating.xls

These are the workbooks that are open in the 1st instance of excel.
How do i look at the workbooks in the 2nd instance.?
property listing.xls
summary.xls

I thought this code might do it, but just keeps looping through the
1st instance, without moving to the 2nd.
Code:
Do
Set XLAPP = GetObject(, "Excel.Application")
If Not XLAPP Is Nothing Then
For Each wkbk In XLAPP.Workbooks
If wkbk.Name = "Property Listing - " &
UserForm2.ComboBox1.Value & ".xls" Then
wkbk.Saved = True
x = wkbk.Path
wkbk.Close
End If
Next wkbk
End If
Loop

So what i want to do is:
open my rating workbook
press the userform button
have a 2nd instance of excel open
have multiple workbooks open to do calculations, leaving only 2
workbooks remaining

so far so good

have x = the path of the propertylisting workbook

x is in the code of the rating workbook userform and i can't get to
read the workbooks that are in the other instance of excel.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Get Workbook path but from another excel instance

Thanks Paul.

Unfortunately it just gets stuck in a loop. I tried stepping through
it and the line
For Each wkbk In XLAPP.Workbooks
does not appear to find any workbooks.

Any other ideas?

George
On 16 Mar, 12:27, wrote:
Hi

Set XLAPP = GetObject(, "Excel.Application")

will return the existing object if one already exists.

You probably want
Set XLAPP = GetObject("", "Excel.Application")

which will return a second object (see the Help for GetObject).

Better still do this in your case:
Dim XLAPP as Excel.Application
Set XLAPP = New Excel.Application

regards
Paul


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Get Workbook path but from another excel instance

Using GetObject like that will return a reference to a (read any) instance
of Excel, possibly the one you are working in.

If you are creating a instance of Excel at the beginning, maintain that
reference and use it again later in your code:

Dim XLApp as excel.application
SEt xlapp=new excel.application

'Do you processing etc

dim XLWB as workbook
for each xlwb in alpp.workbooks

NickHK

wrote in message
oups.com...
I open a rating workbook which, when a userform button is pressed,
opens another instance of excel and runs multiple workbooks that do
many calculations. When this is completed, i want the next part of the
rating code to remember the path for one of the two workbooks that are
left open in the other instance of excel.

When i try looking through the available workbooks, i get:
personal.xls
Book1.xls
rating.xls

These are the workbooks that are open in the 1st instance of excel.
How do i look at the workbooks in the 2nd instance.?
property listing.xls
summary.xls

I thought this code might do it, but just keeps looping through the
1st instance, without moving to the 2nd.
Code:
Do
Set XLAPP = GetObject(, "Excel.Application")
If Not XLAPP Is Nothing Then
For Each wkbk In XLAPP.Workbooks
If wkbk.Name = "Property Listing - " &
UserForm2.ComboBox1.Value & ".xls" Then
wkbk.Saved = True
x = wkbk.Path
wkbk.Close
End If
Next wkbk
End If
Loop


So what i want to do is:
open my rating workbook
press the userform button
have a 2nd instance of excel open
have multiple workbooks open to do calculations, leaving only 2
workbooks remaining

so far so good

have x = the path of the propertylisting workbook

x is in the code of the rating workbook userform and i can't get to
read the workbooks that are in the other instance of excel.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Get Workbook path but from another excel instance

Thanks Paul and Nick.

I was being a bit dim. I had the userform button running a macro that
opened the XLAPP and workbooks, but forgot to make XLAPP public so i
could use it in the userform code.

Looks like i can get it now.
Thanks for taking the time to respond.

George

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force excel to start new instance when I double-click a workbook [email protected][_2_] Excel Discussion (Misc queries) 0 April 30th 09 01:35 PM
find full file path of running excel instance Rama Excel Programming 8 February 12th 07 03:15 PM
Run Macro in another workbook already OPENED in another instance of Excel [email protected] Excel Programming 3 December 27th 06 04:37 AM
How do I get one instance of Excel to communicate with another instance? [email protected] Excel Programming 3 November 21st 06 10:31 PM
Move a workbook from one instance of excel applicaiton to another Alan Excel Programming 2 September 29th 05 04:52 AM


All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"