Skip to Content
Jul 26, 2018 at 03:52 PM

Find and select desired query through Script Registration and Playback

395 Views Last edit Jul 30, 2018 at 04:16 AM 4 rev

Hello everyone! I recently started working with SAP at my stage in the HR industry and the first challenge was to create a macro for Excel VBA that logs into SAP, uses the PAAH transaction and opens / executes a given query and saves the generated data in a worksheet in excel. I was able to create the script for VBA through the Script Registration and Playback tool in SAP and use the macro without problems. But I came across a problem: In script playback it takes the value of the line I selected at the time of recording. If a new query is added in this list of queries, the index of my query will change. My question is how do I always find the desired query and execute it even if the list changes. Below is the code I was using, obtained through the Registration and Playback Script:


Session.findById("wnd[0]/tbar[0]/okcd").Text = "/npaah"

Session.findById("wnd[0]").sendVKey 0



Session.findById("wnd[1]/usr/cmbDYNP4300-DD_WORKSPACE").Key = "1"


Session.findById("wnd[1]/usr/cmbDYNP4300-DD_USERGROUP").Key = "102"

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES").verticalScrollbar.Position = 2835

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES").getAbsoluteRow(2837).Selected = True


Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES/txtDYNP4300_TC_QUERIES-NAME[0,2]").caretPosition = 0


Session.findById("wnd[0]/shellcont[0]/shell").pressToolbarButton "GET_DATA"

Session.findById("wnd[0]/shellcont[0]/shell").pressToolbarContextButton "&MB_EXPORT"

Session.findById("wnd[0]/shellcont[0]/shell").selectContextMenuItem "&XXL"

Session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "P:\Desktop\Teste"

Session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "FUNCIONÁRIOS_SITUAÇÃO.XLSX"

Session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13



1.png (63.9 kB)