title: How to extract PDF document from SAP GUI? (scripting)
body: <p>I am trying to extract a PDF document from SAP, however, I am stuck with the second part of the code where I need to initiate the Save As sequence.</p>
  
  <p>The first part of the code involves connecting to SAP and querying specific invoice number, followed by a few lines of code where I am trying to attach to the second SAP window containing the PDF document. The trick is using the Send Keys to save the actual file.</p>
  
  <pre><code>Sub DocumentExtraction()
  
      Dim varResponse As Variant 'Prompts the user if macro should be run.
          varResponse = MsgBox("Are you sure you wish to run extraction macro?", vbYesNo, "Warning!")
          If varResponse &lt;&gt; vbYes Then Exit Sub
  
      Set SapGuiAuto = GetObject("SAPGUI") 'Obtains SAP GUI Scripting object.
      Set SAPApp = SapGuiAuto.GetScriptingEngine 'Obtains currently running SAP GUI.
      Set SAPCon = SAPApp.Children(0) 'Obtains the first system currently connected.
      Set session = SAPCon.Children(0) 'Obtains the first session (window) on that connection.
  
      ' SAP scripting starts here.
  
      session.findById("wnd[0]").maximize
      session.findById("wnd[0]/tbar[0]/okcd").Text = "/nFB03"
      session.findById("wnd[0]").sendVKey 0
      session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = "930502016"
      session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = "7360"
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = "2019"
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").caretPosition = 4
      session.findById("wnd[0]").sendVKey 0
      session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
      session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
      session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"
      session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").doubleClickCurrentCell
  
      Set session = SAPCon.Children(1) 'Obtains the second session (window) on current connection.
  
      session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").SetFocus
  
  End Sub
  </code></pre>
  
  <p>I have found a similar post on the SAP support page, however, the suggested solution does not seem to work - an object does not exist.</p>