Skip to content

Instantly share code, notes, and snippets.

@bigarabuza
Created March 5, 2019 15:52
Show Gist options
  • Save bigarabuza/fcb7855ccfbdb378bb485fe31755f9d9 to your computer and use it in GitHub Desktop.
Save bigarabuza/fcb7855ccfbdb378bb485fe31755f9d9 to your computer and use it in GitHub Desktop.
Working with SAPGUI Scripting API
'Activate SAP GUI Scripting API in references library.
'If unavailable in reference library, locate file at C:\program files (x86)\sap\frontend\sapgui\sapfewse.ocx
'Refer to SAP GUI Scripting API Documentation:
'https://wiki.scn.sap.com/wiki/display/ATopics/SAP+GUI+Scripting
Sub SAPGUIScripting()
Public objGui As GuiApplication
Public objConn As GuiConnection
Public objSess As GuiSession
Public objSBar As GuiStatusbar
'Get the application object from the Running Object Table
If objGui Is Nothing Then
Set SapGuiAuto = GetObject("SAPGUI")
Set objGui = SapGuiAuto.GetScriptingEngine
End If
'Get the first connection
If objConn Is Nothing Then
Set objConn = objGui.Children(0)
End If
'Get the first session
If objSess Is Nothing Then
Set objSess = objConn.Children(0)
End If
'Enter SAP GUI Scripting
objSess.findById("wnd[0]").maximize
objSess.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00002"
objSess.findById("wnd[0]/tbar[1]/btn[17]").press
objSess.findById("wnd[1]/usr/txtV-LOW").text = "testVariant"
objSess.findById("wnd[1]/usr/txtENAME-LOW").text = ""
objSess.findById("wnd[1]/usr/txtENAME-LOW").setFocus
objSess.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 0
objSess.findById("wnd[1]/tbar[0]/btn[8]").press
objSess.findById("wnd[0]/usr/chkREPTABLE").selected = true
objSess.findById("wnd[0]/usr/radSUBFLAG").select
objSess.findById("wnd[0]/usr/ctxtS_BUKRS-LOW").text = "1111"
objSess.findById("wnd[0]/usr/txtS_GJAHR-LOW").text = "2019"
objSess.findById("wnd[0]/usr/txtS_POPER-LOW").text = "01"
objSess.findById("wnd[0]/usr/txtP_FILE").text = "C:\USERS\bennyboo9\DOCUMENTS\RANDOM PROJECTS\SAP DIH\TEST2.TEXT"
objSess.findById("wnd[0]/usr/txtP_FILE").setFocus
objSess.findById("wnd[0]/usr/txtP_FILE").caretPosition = 60
objSess.findById("wnd[0]/tbar[1]/btn[8]").press
objSess.findById("wnd[0]/tbar[0]/btn[12]").press
objSess.findById("wnd[0]/tbar[0]/btn[12]").press
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment