Extract data from SAP to Excel. Error 619


I have recorded a sequence in SAP, and I have passed the code to the Excel developer. In that sequence, the only thing I intend to do is to open a query about it when opening the Excel workbook. I do not have the loop implemented to get all the rows of the query yet, because I want it to work at least first. It is the first time that I try to automate the export of data from SAP to Excel, the idea is to avoid repeating the process of downloading the query from SAP, and to do it directly when manipulating this Excel. I also know that at the moment I keep it in a txt. (Passing it later to Excel would be minor problems). I do not intend to deal with the error, I want to obtain the data of this transaction daily. I leave the code here:

Private Sub Workbook_Open()

Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
  Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

  'Start the transaction to view a table
  session.StartTransaction "PSG"

  'Select table
     MsgBox "Todo bien"
    session.findById("wnd[0]/usr/ctxtS1_LGNUM").Text = "201"


  'Set our selection criteria
  session.findById("wnd[0]/usr/txtMAX_SEL").Text = "2"

  'Click the export to file button

  'Choose the export format

  'Choose the export filename
    session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\user001\Desktop"
    session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "prueba.txt"

  'Export the file

End Sub

Error 619 comes out when we do the first findById (the MsgBox runs correctly). Skip when we select or change the field to choose the warehouse from which we want to extract the data.

asked by Adrián 27.11.2018 в 10:33

0 answers