title: Input Excel text into fields on HostExplorer mainframe emulator screen
body: <p>I'm working with the HostExplorer mainframe terminal emulator. My VBA knowledge is based on piecing together bits of information I've found online to make other macros. </p>
  
  <p>I'm making a macro to enter an invoice into the mainframe, move between a few screens, input information which will generate a link then use that link to save a file to a predetermined folder on my computer.</p>
  
  <p>I'm stuck at the inputting information part. After navigating to the last screen I need to input text into specific fields in the mainframe.</p>
  
  <p>I know how to identify the location on the screen and use that to create variables. </p>
  
  <p>How can I do the reverse, input a string held in a variable (or just a random letter) to a specific location on the screen?</p>
  
  <pre><code>Sub MiscFileDownload()
  
  Dim HostExplorer As Object
  Dim MyHost As Object
  Dim Rc As Integer
  
  On Error GoTo GenericErrorHandler
  
  Set HostExplorer = CreateObject("HostExplorer") ' Initialize HostExplorer Object
  Set MyHost = HostExplorer.HostFromProfile("*****") ' Set object for the desired session
  If MyHost Is Nothing Then GoTo NoSession
  
  Dim ColALastRow As Long
  ColALastRow = Worksheets(1).Columns("A:A").End(xlDown).Row
  Dim Pro As String
  Dim MiscTest As String
  Dim iPSUpdateTimeout
  
  'enter pro then F2 and F9
  
  For i = 2 To ColALastRow
  
      Pro = Worksheets(1).Cells(i, 1).Value
      Rc = MyHost.Keys(Pro)
      iPSUpdateTimeout = 60
      MyHost.RunCmd ("Enter")
      Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
      If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
      iPSUpdateTimeout = 60
      MyHost.RunCmd ("PF2")
      Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
      If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
      iPSUpdateTimeout = 60
      MyHost.RunCmd ("PF9")
      Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
      If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
      MiscTest = Mid(MyHost.Text, 1466, [3])        
  
      If MiscTest = "YES" Then 'test for Misc if true move to next screen
          Rc = MyHost.Keys("v")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
          MyHost.RunCmd ("Tab")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
          Rc = MyHost.Keys("v")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
          MyHost.RunCmd ("Tab")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
      Else
  
          MyHost.RunCmd ("PF1")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
  
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
          MyHost.RunCmd ("PF1")
          Rc = MyHost.WaitPSUpdated(iPSUpdateTimeout, True)
          If Rc &lt;&gt; 0 Then GoTo OnWaitPSUpdatedTimeout
  
          GoTo NextIteration
      End If
  
  NextIteration:
  Next i
  
  Exit Sub
  </code></pre>