Get PID from Window Handle in Excel (Visual Basic)
Example of GetWindowThreadProcessId: how to get the process Id from of a specific running process using the parent hwnd and Windows API.
Note about Text Formatting
Due to the text markup language in use on Guidespot, some of the characters namely quotes, double dashes, and apostrophies, are changed to a different character encoding which may be incompatable with your vb compiler. As such, all source code in a form which can be compiled is provided in the link below.
Download Sample Code
Special Thanks to Datafilehost.com for providing a service that allows me to make clean code available for download. You Rock!
Visual Basic Declaration
Private Declare Function GetWindowThreadProcessId Lib “user32” _
(ByVal hwnd As Long, _
PID As Long) As Long
GetPIDFromHWND Function Example
’Insert function
Public Function _
GetPID(Byval hwnd as Long) as Long
Dim Result
Result = _
GetWindowThreadProcessId(hwnd, GetPID)
End Function
Usage in Excel
Sub Test()
Dim XLPID as Long
XLPID = GetPID(Application.hwnd)
Msgbox XLPID
End Sub
Guides We Think You'll Like
About The Author
Capital Hill, Denver
I should have taken the blue pill.
Explore
Categories In This Guide
Discussions