How To: Get hWnd from a Process ID

  • Thread starter Thread starter Kevin McCartney
  • Start date Start date
K

Kevin McCartney

Hi Michel
Thanks for your help but what happens if I have several
Excel sessions running how do I now which one is the one
I'm looking for to destroy?

I'd really like to be able to pass the Process ID to a
function. Do you know of function that allows this?

Thanks for your time
KM
 
Hi,
You might want to use a function such as this to 'set' your excel variable.
If an instance of excel is already running, it will use that, otherwise it creates
a new instance.

Function InitializeExcel() As Boolean

On Error Resume Next
Set golApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set golApp = CreateObject("Excel.Application")
On Error GoTo Init_Err
End If

InitializeExcel = True
Init_Bye:

Exit Function
Init_Err:
InitializeExcel = False
Resume Init_Bye

End Function
 
Back
Top