Function CheckNumberOfSAPSessions() As Integer Dim sap As Object Dim sapGui As Object Dim sapCon As Object Dim sapSession As Object Dim i As Integer Dim j As Integer Dim AnzahlSAPSessions As Integer AnzahlSAPSessions = 0 Dim vartemp(10000, 3) As Variant Set sap = GetObject("sapgui") Set sapGui = sap.getscriptingEngine 'loop through open connection For i = 0 To sapGui.Connections.count - 1 Set sapCon = sapGui.Children(CLng(i)) 'loop through sessions on the connection For j = 0 To sapCon.sessions.count - 1 Set sapSession = sapCon.Children(CLng(j)) 'list down the info With sapSession.info vartemp(j, 1) = .systemname vartemp(j, 2) = .sessionnumber vartemp(j, 3) = .transaction AnzahlSAPSessions = AnzahlSAPSessions + 1 End With Next j Next i Set sapSession = Nothing Set sapCon = Nothing Set sapGui = Nothing Set sap = Nothing CheckNumberOfSAPSessions = AnzahlSAPSessions End Function Sub SAPAutomatisieren() Dim Datevon, Datebis As Date Dim SapGuiAuto As Object Dim SAPApp As Object Dim sapCon As Object Dim session As Object If CheckNumberOfSAPSessions > 0 Then UF_Datumswahl.Show Datevon = Sheets("Board").Cells(9, 2) Datebis = Sheets("Board").Cells(10, 2) 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 '########################################################################################################### 'I NEED EXPLANATION FROM HERE session.findById("wnd[0]/tbar[0]/okcd").Text = "/n" 'Zurück ins Hauptmenü befehl session.findById("wnd[0]").sendVKey 0 'Befehl ausführen session.findById("wnd[0]/tbar[0]/okcd").Text = "zfmz" 'Befehl material anzeigen session.findById("wnd[0]").sendVKey 0 'Befehl ausführen session.findById("wnd[0]/usr/ctxtS_QMART-LOW").Text = "q3" 'session.findById("wnd[0]/usr/ctxtS_QMART-HIGH").Text = "q3" session.findById("wnd[0]/usr/ctxtS_QMDAT-LOW").Text = Datevon session.findById("wnd[0]/usr/ctxtS_QMDAT-HIGH").Text = Datebis session.findById("wnd[0]/usr/ctxtP_VAR").Text = "/Q-TISCH" session.findById("wnd[0]/usr/ctxtS_MATNR-LOW").SetFocus session.findById("wnd[0]/usr/ctxtS_QMDAT-HIGH").caretPosition = 10 session.findById("wnd[0]/tbar[1]/btn[8]").press 'Filter Löschvermerk setzen session.findById("wnd[0]").maximize session.findById("wnd[0]/tbar[1]/btn[38]").press session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").currentCellRow = -1 session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").selectColumn "SELTEXT" session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").pressColumnHeader "SELTEXT" session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").currentCellRow = 128 session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").firstVisibleRow = 117 session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/cntlCONTAINER1_FILT/shellcont/shell").selectedRows = "128" session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/btnAPP_WL_SING").press session.findById("wnd[1]/usr/subSUB_CONFIGURATION:SAPLSALV_CUL_FILTER_CRITERIA:0600/btn600_BUTTON").press session.findById("wnd[2]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").press session.findById("wnd[3]/usr/tabsTAB_STRIP/tabpNOSV").Select session.findById("wnd[3]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL_255-SLOW_E[1,0]").Text = "LÖVM" session.findById("wnd[3]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL_255-SLOW_E[1,0]").caretPosition = 5 session.findById("wnd[3]/tbar[0]/btn[8]").press session.findById("wnd[2]/tbar[0]/btn[0]").press 'Tabelle exportieren session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").Select session.findById("wnd[1]/tbar[0]/btn[0]").press session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "O:\Bereich_Q\Fehlermanagement\Q_Tisch\Auswertungen\Ampelliste\Abfragedatei\" session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "Fehlermeldung_Q-Tisch.dat" session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13 session.findById("wnd[1]/tbar[0]/btn[11]").press 'I NEED EXPLANATION UP TO HERE '########################################################################################################### Set SapGuiAuto = Nothing Set SAPApp = Nothing Set sapCon = Nothing Set session = Nothing Sheets("Board").Activate Else MsgBox ("Bitte SAP-Session starten") End End If End Sub
I am new in programming with SAP Script and I just took over the code of a colleague. When I run the code (See code attachment) I get the "run time error 613" at the following line
session.findById("wnd[3]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL_255-SLOW_E[1,0]").Text = "LÖVM"
I wish to understand what the code does line after line on the places where I have indicated (see code attachement). I will be very grateful if I could get some help. Immense thanks in advance.
Ndonwi