Hello,
I’m trying to get access to various properties and methods of SAP elements (like this) using UiPath Studio.
I can spy SAP elements via studio but they are UiElement type. And I can only access UiElement class methods and properties.
I’ve tried using the invoke code, but cannot make it work. Although similar code works fine in VBA or VBS, I cannot make it work in the UiPath.
The VB.net code is following, this is just a simple connector to an existing SAP instance:
Dim SapGuiAuto As Object
Dim SAPApp As GuiApplication
Dim SAPCon As GuiConnection
Dim session As GuiSession
SapGuiAuto = GetObject("SAPGUI")
SAPApp = SapGuiAuto.GetScriptingEngine
SAPCon = SAPApp.Children(0)
session = SAPCon.Children(0)
I’ve imported the ‘sapfewse.ocx’ library into my project to have required references, but I’m keep getting the following error:
Error ERROR Validation Error No compiled code to run
error BC30574: Option Strict On disallows late binding. At line 7
error BC30512: Option Strict On disallows implicit conversions from ‘Object’ to ‘sapfewse.GuiConnection’. At line 8
error BC30512: Option Strict On disallows implicit conversions from ‘Object’ to ‘sapfewse.GuiSession’. At line 9 Main.xaml
Changing all variable types to ‘Object’ doesn’t help either as I only get error about late binding…
I could make external VBS or VBA file script and run it from the Studio, but this is not the way I want to solve it. I would prefer to not use any external files and stick only to the Studio.
Does anyone have any other idea on how to access SAP GUI elements’ properties and methods from the UiPath Studio? Or how to make invoke code working with SAP GUI Scripting?
HI @Faymlor
I would love to understand the use case! What you would like to achieve?
UiPath Platform is low-code/no-code, it means we are doing all to help customer to automate SAP in the most easier way, with no single line of code
Best regards, Lev
@Faymlor
Hello Faymlor,
welcome in the UiPath Community.
You want to use late binding, but this is not possible inside a invoke code activity. Here a tiny tip how to realize the using of late binding.
But this is not the right way, as @LevKushnir described. Please visit the UiPath Academy and take the great course SAP Automation. This course is for everybody interested in automating SAP Business Processes within SAP WinGUI.

Best regards
Stefan
Thank you for all the information. Yes, I’ve already saw the training and ‘Supported SAP Elements’ article.
My use case would be as following:
There is a large table in SAP (GuiTableControl to be specific) which can be scrolled down.
We need to analyze each row and basing on business rules double click to select it or not.
Now, the number of visible rows on screen varies depending on SAP window size.
In normal situation, basing on values from ‘RowCount’ and ‘VisibleRowCount’ properties of the table object, I would loop through all visible rows, make decision if next page key should be send and perform next loop iteration if needed.
However, I’m struggling to achieve that in UIPath…
I can get all rows count by finding the table in Studio and accessing its ‘rowsCount’ parameter. I can read whole table as well with ‘Extract Table Data’ activity. But this activity automatically scrolls down to read whole table (which might be quite handful as well) and I can’t find a way to stop it. I could read whole table and then scroll to the top. But still, I don’t know how many rows are currently visible on the screen, so when looping through all the read data, I don’t know when to scroll the table.
@Faymlor
Hello Faymlor,
the activity Get Attribute delivers a lot of information about an SAP GuiTableControl, but not all. You can use a work around to handle your requirement, an additional VBScript. The script detects the session via SystemSessionID and SessionNumber. Both information delivers the Get Attribute activity. It loops over all connections and sessions to find the correct one. When it has found the right session it calls the Sub Action. In this sub routine you can use the attributes which are not supported by the Get Attribute activity, in your case VisibleRowCount.
'-Begin-----------------------------------------------------------------
'-Directives------------------------------------------------------------
Option Explicit
'-Sub Action------------------------------------------------------------
Sub Action(session)
Dim Id, oElement
Id = "wnd[0]/" + WScript.Arguments.Item(2)
Set oElement = session.findById(Id)
WScript.Echo CStr(oElement.VisibleRowCount)
End Sub
'-Sub GetSession--------------------------------------------------------
Sub GetSession(SessionID, SessionNumber)
Dim SapAppl, SapGuiAuto, CollCon, i, oCon, CollSes, j, oSes
Dim oSesInf, SessID, SessNumber
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
WScript.Echo "Error: GetObject"
Exit Sub
End If
Set SapAppl = SapGuiAuto.GetScriptingEngine
If Not IsObject(SapAppl) Then
WScript.Echo "Error: GetScriptingEngine"
Exit Sub
End If
Set CollCon = SapAppl.Connections()
If Not IsObject(CollCon) Then
WScript.Echo "Error: No Connections"
Exit Sub
End If
'-Loop over connections-----------------------------------------------
For i = 0 To CollCon.Count() - 1
Set oCon = SapAppl.Children(CLng(i))
If Not IsObject(oCon) Then
WScript.Echo "Error at Connection"
Exit Sub
End If
Set CollSes = oCon.Sessions()
If Not IsObject(CollSes) Then
WScript.Echo "Error: No Sessions"
Exit Sub
End If
'-Loop over sessions------------------------------------------------
For j = 0 To CollSes.Count() - 1
Set oSes = oCon.Children(CLng(j))
If Not IsObject(oSes) Then
WScript.Echo "Error at Session"
Exit Sub
End If
If oSes.Busy() = vbFalse Then
Set oSesInf = oSes.Info()
If IsObject(oSesInf) Then
SessID = oSesInf.SystemSessionID()
SessNumber = CStr(oSesInf.SessionNumber() - 1)
If SessID = SessionID And SessNumber = SessionNumber Then
Action oSes
End If
End If
End If
Next
Next
End Sub
'-Sub Main--------------------------------------------------------------
Sub Main()
GetSession WScript.Arguments.Item(0), WScript.Arguments.Item(1)
End Sub
'-Main------------------------------------------------------------------
Main
'-End-------------------------------------------------------------------
In the UiPath workflow I detect at first the attributes SystemSessionId, SessionNumber and the ID of the UI element, in my case a table control.
Then I call the script with the parameters.
In my example I use a simple table.
Here the result.

With this tiny work around you can combine UiPath possibilities with the full SAP GUI Scripting possibilities.
Best regards
Stefan
Hi Stefan,
Thank you for the code and instructions.
Although it’s based on external script file, which from the beginning I knew can solve the issue, but I wanted to avoid it and do everything in UiPath, I think it is the best solution for now.
Once again thank you for your time and all help.