Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default GetObject when more than 1 Excel is running

As already suggested, where the filename is known use GetObject to reference
the workbook then attach to the parent application.

For situations where there is no known loaded wb, Jialiang Ge appears to
have demonstrated how to find multiple instances with .net

For VBA, I have two methods, briefly:

The first enumerates Excel windows, then workbook windows to find the file
name of a loaded wb. Having got that try GetObject parent. If that fails,
eg no loaded workbooks at all or some other reason, use DDE (from a helper
app) to add a new dummy hidden wb and try again.

The other way is finding in the ROT (clever stuff, not mine!) There are
dis/advantages with each. Via the ROT is faster but can't get be sure to get
all instances, eg no loaded wb as can with DDE (usually!).

If anyone is interested I have a demo that implements both methods. Having
got the ref's the withevents xlApp classes can track and record changes to
cells in all wb's in all instances, and one or two other things.

Regards,
Peter T
pmbthornton gmail com



"Ed White" wrote in message
...
From within VB.Net, if I want to access an instance of Excel that is

already
running, I'd use something like.
dim Exc as Excel.Application
Exc = GetObject(, "Excel.Application")

However, suppose I have more than one instance of Excel open. Is there a
way to cycle through each open instance, and to pick a specific one to

open?
--
Ed



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default enumerates Excel windows

Can you share code that enumerates multiple Excel windows.



Peter T wrote:

As already suggested, where the filename is known use GetObject to
23-Jul-08

As already suggested, where the filename is known use GetObject to reference
the workbook then attach to the parent application.

For situations where there is no known loaded wb, Jialiang Ge appears to
have demonstrated how to find multiple instances with .net

For VBA, I have two methods, briefly:

The first enumerates Excel windows, then workbook windows to find the file
name of a loaded wb. Having got that try GetObject parent. If that fails,
eg no loaded workbooks at all or some other reason, use DDE (from a helper
app) to add a new dummy hidden wb and try again.

The other way is finding in the ROT (clever stuff, not mine!) There are
dis/advantages with each. Via the ROT is faster but can't get be sure to get
all instances, eg no loaded wb as can with DDE (usually!).

If anyone is interested I have a demo that implements both methods. Having
got the ref's the withevents xlApp classes can track and record changes to
cells in all wb's in all instances, and one or two other things.

Regards,
Peter T
pmbthornton gmail com



"Ed White" wrote in message
...
already
open?

Previous Posts In This Thread:

On Tuesday, July 22, 2008 6:41 PM
ewhit wrote:

GetObject when more than 1 Excel is running
From within VB.Net, if I want to access an instance of Excel that is already
running, I'd use something like.
dim Exc as Excel.Application
Exc = GetObject(, "Excel.Application")

However, suppose I have more than one instance of Excel open. Is there a
way to cycle through each open instance, and to pick a specific one to open?
--
Ed

On Tuesday, July 22, 2008 10:49 PM
Doug Glancy wrote:

GetObject when more than 1 Excel is running
Ed,

Check out this page:
http://support.microsoft.com/kb/288902

Here's the relevant part:
You can attach to a specific instance if you know the name of an open
document in that instance. For example, if an instance of Excel is running
with an open workbook named Book2, the following code attaches successfully
to that instance even if it is not the earliest instance that was launched:
Set xlApp = GetObject("Book2").Application

Depending on what you're doing you might consider using CreateObject instead
and opening the file you are interested in. I think that's generally
considered a safer practice.
hth,

Doug

"Ed White" wrote in message
...

On Wednesday, July 23, 2008 8:35 AM
Peter T wrote:

As already suggested, where the filename is known use GetObject to
As already suggested, where the filename is known use GetObject to reference
the workbook then attach to the parent application.

For situations where there is no known loaded wb, Jialiang Ge appears to
have demonstrated how to find multiple instances with .net

For VBA, I have two methods, briefly:

The first enumerates Excel windows, then workbook windows to find the file
name of a loaded wb. Having got that try GetObject parent. If that fails,
eg no loaded workbooks at all or some other reason, use DDE (from a helper
app) to add a new dummy hidden wb and try again.

The other way is finding in the ROT (clever stuff, not mine!) There are
dis/advantages with each. Via the ROT is faster but can't get be sure to get
all instances, eg no loaded wb as can with DDE (usually!).

If anyone is interested I have a demo that implements both methods. Having
got the ref's the withevents xlApp classes can track and record changes to
cells in all wb's in all instances, and one or two other things.

Regards,
Peter T
pmbthornton gmail com



"Ed White" wrote in message
...
already
open?


Submitted via EggHeadCafe - Software Developer Portal of Choice
Xcompress - IIS HTTP Compression
http://www.eggheadcafe.com/tutorials...http-comp.aspx
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default enumerates Excel windows

One way -

Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long

Sub test()
Dim i As Long
Dim arrXLhWnd() As Long

If GetXLhWnds(arrXLhWnd) Then
For i = LBound(arrXLhWnd) To UBound(arrXLhWnd)
Debug.Print arrXLhWnd(i)
Next
End If

End Sub

Function GetXLhWnds(arrXLhWnd() As Long) as Long
Dim n As Long
Dim hWndXL As Long, hWndDT As Long

ReDim arrXLhWnd(1 To 100) ' cater for 100 potential Excelinstances
hWndDT = GetDesktopWindow

Do
hWndXL = FindWindowEx(hWndDT, hWndXL, "XLMAIN", vbNullString)
If hWndXL Then
n = n + 1
arrXLhWnd(n) = hWndXL
End If
Loop Until hWndXL = 0

If n Then
ReDim Preserve arrXLhWnd(1 To n)
GetXLhWnds = n
Else
Erase arrXLhWnd
End If

End Function

Regards,
Peter T


<Obaid Ullah wrote in message ...
Can you share code that enumerates multiple Excel windows.



Peter T wrote:

As already suggested, where the filename is known use GetObject to
23-Jul-08

As already suggested, where the filename is known use GetObject to
reference
the workbook then attach to the parent application.

For situations where there is no known loaded wb, Jialiang Ge appears to
have demonstrated how to find multiple instances with .net

For VBA, I have two methods, briefly:

The first enumerates Excel windows, then workbook windows to find the file
name of a loaded wb. Having got that try GetObject parent. If that
fails,
eg no loaded workbooks at all or some other reason, use DDE (from a helper
app) to add a new dummy hidden wb and try again.

The other way is finding in the ROT (clever stuff, not mine!) There are
dis/advantages with each. Via the ROT is faster but can't get be sure to
get
all instances, eg no loaded wb as can with DDE (usually!).

If anyone is interested I have a demo that implements both methods. Having
got the ref's the withevents xlApp classes can track and record changes to
cells in all wb's in all instances, and one or two other things.

Regards,
Peter T
pmbthornton gmail com



"Ed White" wrote in message
...
already
open?

Previous Posts In This Thread:

On Tuesday, July 22, 2008 6:41 PM
ewhit wrote:

GetObject when more than 1 Excel is running
From within VB.Net, if I want to access an instance of Excel that is
already
running, I'd use something like.
dim Exc as Excel.Application
Exc = GetObject(, "Excel.Application")

However, suppose I have more than one instance of Excel open. Is there a
way to cycle through each open instance, and to pick a specific one to
open?
--
Ed

On Tuesday, July 22, 2008 10:49 PM
Doug Glancy wrote:

GetObject when more than 1 Excel is running
Ed,

Check out this page:
http://support.microsoft.com/kb/288902

Here's the relevant part:
You can attach to a specific instance if you know the name of an open
document in that instance. For example, if an instance of Excel is running
with an open workbook named Book2, the following code attaches
successfully
to that instance even if it is not the earliest instance that was
launched:
Set xlApp = GetObject("Book2").Application

Depending on what you're doing you might consider using CreateObject
instead
and opening the file you are interested in. I think that's generally
considered a safer practice.
hth,

Doug

"Ed White" wrote in message
...

On Wednesday, July 23, 2008 8:35 AM
Peter T wrote:

As already suggested, where the filename is known use GetObject to
As already suggested, where the filename is known use GetObject to
reference
the workbook then attach to the parent application.

For situations where there is no known loaded wb, Jialiang Ge appears to
have demonstrated how to find multiple instances with .net

For VBA, I have two methods, briefly:

The first enumerates Excel windows, then workbook windows to find the file
name of a loaded wb. Having got that try GetObject parent. If that
fails,
eg no loaded workbooks at all or some other reason, use DDE (from a helper
app) to add a new dummy hidden wb and try again.

The other way is finding in the ROT (clever stuff, not mine!) There are
dis/advantages with each. Via the ROT is faster but can't get be sure to
get
all instances, eg no loaded wb as can with DDE (usually!).

If anyone is interested I have a demo that implements both methods. Having
got the ref's the withevents xlApp classes can track and record changes to
cells in all wb's in all instances, and one or two other things.

Regards,
Peter T
pmbthornton gmail com



"Ed White" wrote in message
...
already
open?


Submitted via EggHeadCafe - Software Developer Portal of Choice
Xcompress - IIS HTTP Compression
http://www.eggheadcafe.com/tutorials...http-comp.aspx



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
Using Excel templates with GetObject/CreateObject jille Excel Programming 1 February 16th 07 09:08 PM
Help Please: Run Excel based sub from Access using GetObject Perico[_2_] Excel Programming 3 October 19th 06 04:24 PM
GetObject method from excel to other application from remote server sandra mangunsong via OfficeKB.com Excel Programming 1 February 24th 05 07:13 PM
Controlling Reflection1 from Excel using getObject Michael Nisgore Excel Programming 0 March 3rd 04 03:30 AM
Excel Getobject error Jaya Excel Programming 4 July 17th 03 07:13 PM


All times are GMT +1. The time now is 06:11 AM.

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

About Us

"It's about Microsoft Excel"