title: Excel keeps "running" while asking SAP GUI to export spreadsheet
body: <p>I have a problem with a Excel VBA code that constantly get stuck in 'running' when I execute the code, see figure <img src="https://i.stack.imgur.com/qND92.png" alt="Stuck Excel;" /></p>
  <p>The Purpose of the code is:</p>
  <ol>
  <li>Log into SAP</li>
  <li>Execute a transaction (in this case IW73)</li>
  <li>Export a Spreadsheet as .txt</li>
  </ol>
  <p>The Problem after closing the SAP session the Excel get stuck in &quot;Running&quot;. We have tried running it on different computers with the same (Stuck in 'Running') error.</p>
  <p>Code:</p>
  <pre><code> Sub Logontrial()
   Dim SapGuiApp As Object
   Dim oConnection As Object
   Dim SAPCon As Object, SAPSesi As Object
   Dim SapGuiAuto As Object, SAPApp As Object
  
  
   If SapGuiApp Is Nothing Then
    Set SapGuiApp = CreateObject(&quot;Sapgui.ScriptingCtrl.1&quot;)
   End If
  
   If oConnection Is Nothing Then
      Set oConnection = SapGuiApp.OpenConnection(&quot;5.1.1 AP1 ERP Production&quot;, True)
   End If
  
    If SAPSesi Is Nothing Then
       Set SAPSesi = oConnection.Children(0)
    End If
  
    Application.DisplayAlerts = False
  
    With SAPSesi
  
  SAPSesi.findById(&quot;wnd[0]/usr/txtRSYST-MANDT&quot;).Text = &quot;500&quot;
  SAPSesi.findById(&quot;wnd[0]/usr/txtRSYST-BNAME&quot;).Text = &quot;UserName&quot;
  SAPSesi.findById(&quot;wnd[0]/usr/pwdRSYST-BCODE&quot;).Text = &quot;Password&quot;
  SAPSesi.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).Text = &quot;EN&quot;
  SAPSesi.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).SetFocus
  SAPSesi.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).caretPosition = 2
  SAPSesi.findById(&quot;wnd[0]&quot;).sendVKey 0
  
  
   '  start extraction
     On Error GoTo Resume1
     ' DoEvents
     SAPSesi.findById(&quot;wnd[0]&quot;).maximize
     SAPSesi.findById(&quot;wnd[0]/tbar[0]/okcd&quot;).Text = &quot;/nIW73&quot;
     SAPSesi.findById(&quot;wnd[0]&quot;).sendVKey 0
     SAPSesi.findById(&quot;wnd[0]/usr/ctxtSWERK-LOW&quot;).Text = &quot;GB10&quot;
     SAPSesi.findById(&quot;wnd[0]/usr/ctxtSWERK-LOW&quot;).SetFocus
     SAPSesi.findById(&quot;wnd[0]/usr/ctxtSWERK-LOW&quot;).caretPosition = 4
     SAPSesi.findById(&quot;wnd[0]&quot;).sendVKey 8
     SAPSesi.findById(&quot;wnd[0]&quot;).sendVKey 0
     SAPSesi.findById(&quot;wnd[0]/mbar/menu[0]/menu[11]/menu[2]&quot;).Select
     SAPSesi.findById(&quot;wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]&quot;).Select
     SAPSesi.findById(&quot;wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]&quot;).SetFocus
     SAPSesi.findById(&quot;wnd[1]/tbar[0]/btn[0]&quot;).press
     SAPSesi.findById(&quot;wnd[1]/usr/ctxtDY_FILENAME&quot;).Text = &quot;DataImport1.txt&quot;
     SAPSesi.findById(&quot;wnd[1]/usr/ctxtDY_FILENAME&quot;).caretPosition = 15
     SAPSesi.findById(&quot;wnd[1]/tbar[0]/btn[11]&quot;).press
     SAPSesi.findById(&quot;wnd[0]/tbar[0]/okcd&quot;).Text = &quot;/n&quot;
     SAPSesi.findById(&quot;wnd[0]&quot;).sendVKey 0
  
     Set SAPSesi = Nothing
     Set oConnection = Nothing
     Set SapGuiApp = Nothing
     End With
  
    ' This part after closing the SAP session it get stuck.
  
    Resume1:
  
     Application.DisplayAlerts = True
     Set SAPSesi = Nothing
     Set oConnection = Nothing
     Set SapGuiApp = Nothing
    Exit Sub
    End Sub
  </code></pre>
  <p>Thanks in advance</p>
  <p>//Patrick</p>