Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Referenz to running excel application
Hello,
I found this similar code in the newsgroups to find all running excel applications: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then '??? End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 Ok, that works. But now I want to get a reference to each of the running instances to check which workbooks are open (please see the questionmarks). I don`t know, how to get a reference to a running "window". Can anybody help me? -- Peter Marchert [EDV-Service Marchert] Homepage: http://www.marchert.de Excel- und Outlookprogrammierung |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Referenz to running excel application
Peter,
Check out this earlier reply by another Peter for the same thing : http://groups.google.co.uk/group/mic...5cd869da1fa056 NickHK "Peter Marchert" groups.com... Hello, I found this similar code in the newsgroups to find all running excel applications: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then '??? End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 Ok, that works. But now I want to get a reference to each of the running instances to check which workbooks are open (please see the questionmarks). I don`t know, how to get a reference to a running "window". Can anybody help me? -- Peter Marchert [EDV-Service Marchert] Homepage: http://www.marchert.de Excel- und Outlookprogrammierung |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Referenz to running excel application
Hello Nick,
thanks for that link. I now have a solution that works fine for me: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then lngReturn = GetWindowTextLength(lngHandle) If lngReturn 0 Then If lngReturn 256 Then lngReturn = 255 strWindowText = Space$(lngReturn + 1) GetWindowText lngHandle, strWindowText, Len(strWindowText) strWindowText = Left$(strWindowText, lngReturn) If InStr(strWindowText, PROGNAME & ".xls") Then BringWindowToTop lngHandle Set m_objExcel = GetObject(, "Excel.Application") If Not m_objExcel Is Nothing Then Exit Function End If End If End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 I`m just searching for the windowtitle and can get the right application with the "GetObject"-Method. I do not know if the "BringWindowToTop" realy is necessary. Peter NickHK schrieb: Peter, Check out this earlier reply by another Peter for the same thing : http://groups.google.co.uk/group/mic...5cd869da1fa056 NickHK "Peter Marchert" groups.com... Hello, I found this similar code in the newsgroups to find all running excel applications: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then '??? End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 Ok, that works. But now I want to get a reference to each of the running instances to check which workbooks are open (please see the questionmarks). I don`t know, how to get a reference to a running "window". Can anybody help me? -- Peter Marchert [EDV-Service Marchert] Homepage: http://www.marchert.de Excel- und Outlookprogrammierung |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Referenz to running excel application
Hi Peter,
I fear your are wandering down a well trodden path that leads to a dead end! Bringing instances to the front is not going to determine how GetObject works (AFAIK). Though if you want to try I'd use SetForegroundWindow and/or SetWindowPos (caveats with each) rather than BringWindowToTop. Doesn't GetWindowText get the windowtitle you say you are looking for, or if you need loaded file names also enumerate the child & grandchild windows of XLMAIN, XLDESK & EXCEL7 respectively (assumes captions haven't been changed). The point, as I tried to explain in the thread Nick referred you to, GetObject(app) will get (effectively) a random instance irrespective of it's Window position; GetObject(loaded file) and hence its parent app needs the file's fullname, ie path/name. The only relatively reliable way I know in purely VBA is as described in the other thread, though I've noticed others in this ng have alluded to different methods but not shared. Regards, Peter T "Peter Marchert" wrote in message oups.com... Hello Nick, thanks for that link. I now have a solution that works fine for me: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then lngReturn = GetWindowTextLength(lngHandle) If lngReturn 0 Then If lngReturn 256 Then lngReturn = 255 strWindowText = Space$(lngReturn + 1) GetWindowText lngHandle, strWindowText, Len(strWindowText) strWindowText = Left$(strWindowText, lngReturn) If InStr(strWindowText, PROGNAME & ".xls") Then BringWindowToTop lngHandle Set m_objExcel = GetObject(, "Excel.Application") If Not m_objExcel Is Nothing Then Exit Function End If End If End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 I`m just searching for the windowtitle and can get the right application with the "GetObject"-Method. I do not know if the "BringWindowToTop" realy is necessary. Peter NickHK schrieb: Peter, Check out this earlier reply by another Peter for the same thing : http://groups.google.co.uk/group/mic...mming/browse_t hread/thread/acd39310cc60d49d/cb5cd869da1fa056?lnk=st&q=group%3Amicrosoft.pu blic.excel.programming+author%3APeter&rnum=14&hl=e n#cb5cd869da1fa056 NickHK "Peter Marchert" groups.com... Hello, I found this similar code in the newsgroups to find all running excel applications: lngHandle = GetWindow(GetDesktopWindow, GW_CHILD) Do strClassName = String(51, 0) lngMaxCount = GetClassName(lngHandle, strClassName, 50) If UCase(Left(strClassName, lngMaxCount)) = "XLMAIN" Then '??? End If lngHandle = GetWindow(lngHandle, GW_HWNDNEXT) Loop While lngHandle < 0 Ok, that works. But now I want to get a reference to each of the running instances to check which workbooks are open (please see the questionmarks). I don`t know, how to get a reference to a running "window". Can anybody help me? -- Peter Marchert [EDV-Service Marchert] Homepage: http://www.marchert.de Excel- und Outlookprogrammierung |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel still running in task manager after closing the application | Excel Discussion (Misc queries) | |||
Running Excel 2000 VBA Application on Excel 2003 | Excel Worksheet Functions | |||
Excel VBA Macro Running DOS Application !! | Excel Programming | |||
Running excel as an application | Excel Programming | |||
Find all running Excel Application objects | Excel Programming |