title: VBA sending API calls to External program
body: <p>I'm quite new to this and have been fumbling my way through creating an excel document that communicates with one of our external applications.</p>
  
  <p>I've been through a tutorial of using FindWindowEX to find the specific buttons/boxes of this application and have managed to successfully insert text into one of the forms.</p>
  
  <p>I hit a roadblock when trying to "click" a button, and i think the problem is that the application i'm trying to communicate with doesnt have unique class names.</p>
  
  <p><a href="https://i.stack.imgur.com/pvTKt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pvTKt.jpg" alt="enter image description here"></a></p>
  
  <p>From the picture you can see that almost everything is called "WindowsForms10.Window.8.app.0.2004eee"</p>
  
  <p>Which means that i can insert text into the very first and only text box but can't dive any deeper to get hold of the buttons which i need to "click" in order to search.</p>
  
  <p>Current code is as follows: I don't need to open the application as it is always up from startup.</p>
  
  <pre><code>Sub Runapplication()
  
  
  DoEvents
  Hwindow2 = FindWindow(vbNullString, "General Account Enquiry")
  
  
  'Account Number
  Account_Number = FindWindowEx(Hwindow2, 0&amp;, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
  Accountnumber = ThisWorkbook.Sheets("Sheet1").Range("A1")
  
  Call SendMessageByString(Account_Number, WM_SETTEXT, 0, Accountnumber)
  
  
  DoEvents
  
  
  Account1 = FindWindow(vbNullString, "csEditAccount")
  Account = FindWindowEx(Hwindow2, 0&amp;, "WindowsForms10.Window.8.app.0.2004eee", vbNullString)
  
  'Call EnableWindow(Account, True)
  Call SendMessage(Account, WM_LBUTTONDOWN, 0, ByVal 0&amp;)
  
  
  End Sub
  </code></pre>
  
  <p>I have all the constants/declrations</p>
  
  <pre><code>Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
              ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  
  Public Declare PtrSafe Function CloseWindow Lib "user32" (ByVal hWnd As Long) As Long
  
  Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
              ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
              lParam As Any) As Long
  
  Public Declare PtrSafe Function SendMessageByString Lib "user32" Alias "SendMessageA" ( _
              ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
              ByVal lParam As String) As Long
  
   Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
              ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
              ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  
  
  Public Declare PtrSafe Function FindWindowEx Lib "user32" _
              Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
              ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  
  Public Declare PtrSafe Function EnableWindow Lib "USER32.dll" ( _
              ByVal hWnd As Long, _
              ByVal fEnable As Long) As Long
  
  
              Public Const SW_NORMAL As Long = 1
              Public Const WM_CLOSE As Long = &amp;H10
              Public Const BM_CLICK As Long = &amp;HF5
              Public Const WM_KEYUP As Long = &amp;H101
              Public Const WM_SETTEXT = &amp;HC
              Public Const LB_FINDSTRING = &amp;H18F
              Public Const WM_LBUTTONDOWN = &amp;H201
  </code></pre>
  
  <p>Any help would be greatly appreciated, i almost went insane yesterday scouring the internet trying to find an answer to this problem,</p>
  
  <p>Thank you!</p>