Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default List Open Workbooks In All Excel Instances?

How I can get a list of all the open workbooks from among all the running
Excel instances?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default List Open Workbooks In All Excel Instances?

As far as I know you can bring other instances to the forefront, you can list
how many other instances are open and what their handles are BUT VBA doesn't
leap to the new instance and continue running.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown

EXAMPLE:
Private Declare Function GetDesktopWindow Lib "user32" () As Long

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 SwitchToThisWindow Lib "user32" ( _
ByVal hWnd As Long, BOOL As Boolean) As Long

'/========================================/
' Sub Purpose: loop through Excel instances
'/========================================/
'
Public Sub Loop_Thru_Excel_Instances()
Dim varAry()
Dim iInstances As Long 'count of instances for re-dimming
Dim hWndDesk As Long 'Windows handle
Dim hWndXL As Long 'Excel handle
Dim x As Long 'general purpose LONG variable
Dim var As Variant 'general purpose VARIANT variable

On Error GoTo err_Sub

'- - - - - - - - -
'FIND OUT HOW MANY INSTANCES ARE OPEN AND PUT IN ARRAY
'Get a handle for the desktop
hWndDesk = GetDesktopWindow

Do
iInstances = iInstances + 1
hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, _
"XLMAIN", vbNullString)
If hWndXL < 0 Then
ReDim Preserve varAry(iInstances)
'Get the next Excel window
varAry(iInstances) = hWndXL
Else
Exit Do
End If
Loop
'- - - - - - - - -

'example of how to loop thru each instance
For x = 1 To UBound(varAry)
var = SwitchToThisWindow(hWnd:=varAry(x), BOOL:=False)
Next x

'- - - - - - - - -
'example of how to go to the 1st instance
var = SwitchToThisWindow(hWnd:=varAry(1), BOOL:=False)
'- - - - - - - - -

exit_Sub:
On Error Resume Next
Exit Sub

err_Sub:
Debug.Print "Error: " & Err.Number & " - (" & _
Err.Description & _
") - Sub: Loop_Thru_Excel_Instances - Module: " & _
"Mod_Instance_testing - " & Now()
GoTo exit_Sub

End Sub

'/========================================/




"George Lee" wrote:

How I can get a list of all the open workbooks from among all the running
Excel instances?

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
ungroup workbooks into multiple instances of excel Confused Excel Discussion (Misc queries) 2 February 28th 09 07:51 PM
open different workbooks in individual instances of excel ed godlewski Excel Discussion (Misc queries) 1 January 2nd 09 03:37 PM
Create list of unique instances from list of multiple Instances Dishon Excel Worksheet Functions 0 March 3rd 08 10:46 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
Is there an easy way to replace list A instances with list B instances (sorted lists). kkip Excel Programming 3 December 31st 03 01:50 PM


All times are GMT +1. The time now is 11:57 PM.

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"