View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter Marchert Peter Marchert is offline
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