I'm writing a code in Excel VBA to automatically download data from SAP FS10N report. The only problem I have right now is that I can't find any solution to select the layout I wan't to use by the name of the layout. This is the code line I found to be the solution but it doesn't work for me:
Session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell")
Edit: This is the part of my code where I can't access the pop up window which shows the available layouts. And so I can't select any layout by it's name, only the way the script recorder saved the way I did it manually:
session.findById("wnd[0]/tbar[1]/btn[33]").press
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]/usr/lbl[1,12]").setFocus
session.findById("wnd[1]/usr/lbl[1,12]").caretPosition = 3
session.findById("wnd[1]").sendVKey 2
Edit2: This is what my script looks like when recorded:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "fs10n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtSO_SAKNR-LOW").text = "884050"
session.findById("wnd[0]/usr/txtGP_GJAHR").text = "2020"
session.findById("wnd[0]/usr/txtGP_GJAHR").setFocus
session.findById("wnd[0]/usr/txtGP_GJAHR").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").setCurrentCell 1,"BALANCE"
session.findById("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").selectedRows = "1"
session.findById("wnd[0]/usr/cntlFDBL_BALANCE_CONTAINER/shellcont/shell").doubleClickCurrentCell
session.findById("wnd[0]/tbar[1]/btn[33]").press
'My problem starts here
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]").sendVKey 81
session.findById("wnd[1]/usr/lbl[1,12]").setFocus
session.findById("wnd[1]/usr/lbl[1,12]").caretPosition = 2
session.findById("wnd[1]").sendVKey 2
I wan't somehow replace the last seven lines. I wan't to somehow select a layout by it's name in the dialog box. I hope this is more clear now.
Edit3: The line above my comment: session.findById("wnd[0]/tbar1/btn[33]").press Opens the layout select dialog box:
After clicking the button, this dialog box opens:
The last 7 lines of the code are my manual steps scrolling up 4 times, and selecting the wanted layout. Recorder doesn't help me identify the dialog box.
In the ALV Layout Selection Screen, if you know the name of the layout you want to select, do this sequence of actions:
Given the initial list of layouts, click the button Find:
Enter the name of the layout, deselect the checkbox "Starting at current line" to search all lines, and press Enter :
The result should show the layout always at the first row, click it:
The list of all layouts should be scrolled at the right line and the cursor is at the right position, press the key F2
:
All the actions above correspond to the following code (as returned by the Script Recorder):
session.findById("wnd[0]").resizeWorkingPane 158,25,false
session.findById("wnd[0]/tbar[1]/btn[33]").press
session.findById("wnd[1]/tbar[0]/btn[71]").press
session.findById("wnd[2]/usr/chkSCAN_STRING-START").selected = false
session.findById("wnd[2]/usr/txtRSYSF-STRING").text = "/SAP-GLVIEW"
session.findById("wnd[2]/usr/chkSCAN_STRING-START").setFocus
session.findById("wnd[2]/tbar[0]/btn[0]").press
session.findById("wnd[3]/usr/lbl[1,2]").setFocus
session.findById("wnd[3]/usr/lbl[1,2]").caretPosition = 0
session.findById("wnd[3]").sendVKey 2
session.findById("wnd[1]").sendVKey 2