Window Handles


Posted by Mike on December 30, 2001 3:42 PM

What's the syntax to get the window handle of a workbook?

Posted by Jacob on December 30, 2001 6:14 PM


What do you mean?

Jacob

Posted by Ivan F Moala on December 30, 2001 8:33 PM

What Mike is after is the windows handle for
the activewindow which I'm picking is the active
windows handle for excel....if so then this will
get the handle to the activewindow;

Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Sub GetActiveXl_Hwnd()

Dim xlAppCaption As String
Dim hWndXl As Long

xlAppCaption = "Microsoft Excel - " & ActiveWindow.Caption

hWndXl = FindWindow("XLMAIN", xlAppCaption) '

MsgBox "The Activewindow:= " & xlAppCaption & " ) has the Window Handle " & _
vbCrLf & "Hex:=" & Hex(hWndXl) & vbCrLf & _
"Dec:=" & hWndXl & vbCr & vbCrLf & _
"You can use this Window Handle in various Win 32 APIs, " & vbCrLf & _
"such as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr _
& vbCrLf, vbMsgBoxSetForeground
End Sub

HTH


Ivan What do you mean?



Posted by Mike on December 31, 2001 5:40 AM

Thanks Ivan. That's sort of what I was looking for. I knew I could get it through the WIN32 API. I was just wondering if VBA revealed the window handles like VB does, as a property.

But this will work. Thanks again.

-Mike the activewindow which I'm picking is the active windows handle for excel....if so then this will get the handle to the activewindow; (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Dim xlAppCaption As String Dim hWndXl As Long vbCrLf & "Hex:=" & Hex(hWndXl) & vbCrLf & _ "Dec:=" & hWndXl & vbCr & vbCrLf & _ "You can use this Window Handle in various Win 32 APIs, " & vbCrLf & _ "such as SetForeGroundWindow," & vbCr & _ "which require a Window Handle parameter to be supplied." & vbCr _ & vbCrLf, vbMsgBoxSetForeground End Sub

HTH Ivan : : What do you mean? : Jacob