Hi, I have need finf the handles of the first few controls on an external application. All I have is the Window handle. Several discussions I've read have suggested use of the AttachThreadInput API. I tried this code. The Debug.print statement prints h_wnd (the Window handle) all 5 times. Any ideas on how to improve this? Thanks, Bob.
Code:
Dim lngFocusFormThreadID As Long
SetForegroundWindow h_wnd
lngFocusFormThreadID = GetWindowThreadProcessId(h_wnd, ByVal 0&)
Set wshShell = CreateObject("WScript.Shell")
For i = 1 To 5
AttachThreadInput App.ThreadID, lngFocusFormThreadID, True
Debug.Print GetFocus
AttachThreadInput App.ThreadID, lngFocusFormThreadID, False
wshShell.SendKeys "{TAB 1}"
Next
Set wshShell = Nothing