Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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
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
Excel still running in task manager after closing the application Willem Excel Discussion (Misc queries) 0 December 5th 06 01:56 PM
Running Excel 2000 VBA Application on Excel 2003 Excel Worksheet Functions 0 August 8th 06 06:04 PM
Excel VBA Macro Running DOS Application !! monir Excel Programming 11 June 26th 06 03:59 AM
Running excel as an application John[_98_] Excel Programming 8 December 20th 04 06:31 PM
Find all running Excel Application objects news.bluewin.ch Excel Programming 3 February 13th 04 10:28 PM


All times are GMT +1. The time now is 05:40 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"