Hi all,

I am trying to get the handles of the active excel (2007) workbooks on my desktop and I am having some problems.

If excel has only one workbook then everything works fine... If I create an additional workbook (for the same excel instance) then the code below returns 0 as the handle.

Any ideas will be much appreciated.

Cheers,

--Stav.

Code:
 <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
                      ByVal childAfter As IntPtr, _
                      ByVal lclassName As String, _
                      ByVal windowTitle As String) As IntPtr
    End Function

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim processArray As Process()
        Dim exProcId As Integer
        processArray = Process.GetProcessesByName("excel")


        exProcId = processArray(0).Id
        Dim hwnd As IntPtr = (Process.GetProcessById(exProcId).MainWindowHandle)
        Dim cHwnd As IntPtr = FindWindowEx(hwnd, IntPtr.Zero, Nothing, Nothing)



    End Sub