Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a number of instances of Excel running each containing a number of workbooks
One of the instances needs to determine the worksheet names in all the workbooks I can use Application.Workbooks().worksheets().name to get the names from the current instance but I am unable to get the information from all the other instances as I am unable to get an Applicatio handle for each instance Any ideas how I can get the handles to the other instances of Excel Cheers Mark |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Mark,
If you already know the workbooks name you can just use the full pathname instead of the classname. Set MyWorkBook=GetObject("C:\my documents\myfile.xls") If it is a seperate instance, not multipul workbooks in one Excel instance from Windows task list. This code will find all running instances' and you can modify the code to look for a specific instance if you know its name. <http://www.google.com/groups?hl=en&lr=&ie=UTF-8&selm=%23d59pH8nCHA.2288%40TK2MSFTNGP10 -- John johnf 202 at hotmail dot com "Mark Grimes" wrote in message ... | I have a number of instances of Excel running each containing a number of workbooks. | | One of the instances needs to determine the worksheet names in all the workbooks. | | I can use Application.Workbooks().worksheets().name to get the names from the current instance, | but I am unable to get the information from all the other instances as I am unable to get an Application | handle for each instance. | | Any ideas how I can get the handles to the other instances of Excel. | | Cheers, | Mark. | |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for that Joh
However, although it gives me the window handle for all the Excel instances' what I then need to do is to obtain the worksheet names within the Excel instances' I do not know how I can examine the contents of the Excel workbooks in each instanc with only the window handle What I really need is the Application handle for each instance so that I can us Application.Workbooks(x).Worksheets(y).nam Any ideas ? Cheers Mark. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Mark,
We may be too far getting ahead of the problem. "Workbooks" is a collection. So is "Sheets". Once you get a handle to the object it is easy to find the workbooks and sheets within. In the code below MyXL is the object name. Copy & paste the code into a new workbook and run the sub "ListWBSheetNames". ' Declare necessary API routines: Declare Function FindWindow Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName as String, _ ByVal lpWindowName As Long) As Long Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hWnd as Long,ByVal wMsg as Long, _ ByVal wParam as Long, _ ByVal lParam As Long) As Long Dim MyXL As Object ' Variable to hold reference to Microsoft Excel. Dim ExcelWasNotRunning As Boolean ' Flag for final release. Sub GetExcel() ' Test to see if there is a copy of Microsoft Excel already running. On Error Resume Next ' Defer error trapping. ' Getobject function called without the first argument returns a ' reference to an instance of the application. If the application isn't ' running, an error occurs. Set MyXL = Getobject(, "Excel.Application") If Err.Number < 0 Then ExcelWasNotRunning = True Err.Clear ' Clear Err object in case error occurred. ' Check for Microsoft Excel. If Microsoft Excel is running, ' enter it into the Running Object table. DetectExcel ' Set the object variable to reference the file you want to see. Set MyXL = Getobject("c:\vb4\MYTEST.XLS") ' Show Microsoft Excel through its Application property. Then ' show the actual window containing the file using the Windows ' collection of the MyXL object reference. MyXL.Application.Visible = True MyXL.Parent.Windows(1).Visible = True Do manipulations of your file here. ' ... ' If this copy of Microsoft Excel was not running when you ' started, close it using the Application property's Quit method. ' Note that when you try to quit Microsoft Excel, the ' title bar blinks and a message is displayed asking if you ' want to save any loaded files. If ExcelWasNotRunning = True Then MyXL.Application.Quit End IF Set MyXL = Nothing ' Release reference to the ' application and spreadsheet. End Sub Sub DetectExcel() ' Procedure dectects a running Excel and registers it. Const WM_USER = 1024 Dim hWnd As Long ' If Excel is running this API call returns its handle. hWnd = FindWindow("XLMAIN", 0) If hWnd = 0 Then ' 0 means Excel not running. Exit Sub Else ' Excel is running so use the SendMessage API ' function to enter it in the Running Object Table. SendMessage hWnd, WM_USER + 18, 0, 0 End If End Sub Sub ListWBSheetNames() Dim wb, MySheets GetExcel For Each wb In MyXL.Workbooks Debug.Print wb.Name For Each MySheet In MyXL.Sheets Debug.Print MySheet.Name Next Next Debug.Print MyXL.Workbooks.Count, MyXL.Sheets.Count End Sub -- John johnf 202 at hotmail dot com "Mark Grimes" wrote in message ... | Thanks for that John | | However, although it gives me the window handle for all the Excel instances', | what I then need to do is to obtain the worksheet names within the Excel instances'. | | I do not know how I can examine the contents of the Excel workbooks in each instance | with only the window handle. | | What I really need is the Application handle for each instance so that I can use | Application.Workbooks(x).Worksheets(y).name | | Any ideas ?? | | Cheers, | Mark. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How many entries can Excel handle!? | Excel Discussion (Misc queries) | |||
what is "fill handle". i don't see any fill handle in my excel | New Users to Excel | |||
Fill handle turned into a move handle | Excel Discussion (Misc queries) | |||
Am I trying to do something that Excel cannot handle? | Excel Discussion (Misc queries) | |||
macro to close excel application other than application.quit | Excel Programming |