![]() 'Retrieves a handle to the top-level window whose class name and window name match the specified strings. Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr 'Performs an operation on a specified file. Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As LongPtr Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPtr 'Declaring the necessary API functions for both 64 and 32 bit applications. This post is somehow related to these old posts 1, 2: In order to get the list, run GetWindows procedure. ![]() ![]() With following code from Mark Rowlinson (that copied from here, all windows will be reflected, in blocks of 3 columns (handle, ClassName and Caption), very convenient to get the interaction. So the first step should be to detect the open windows -the ones we need to interact with- (and their children), and get them in a worksheet (or wherever you want to output). VBA can be used to explore process and windows, and once we know the window handle (or the caption and ClassName of it), we can focus on that component and send keys specifically to that window, via SendMessage/PostMessage The usual and ‘inconvenient’ way to do so is via the SendKeys API, but it’s not the only one option out there. We can interact with Windows’s windows (sic) from within VBA, even if there is not a OCX we can set a reference to and deal with the external application.
0 Comments
Leave a Reply. |