Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan-Schnell
Active Contributor
21,000
In a few cases it is in business context not allowed to install additional analyze software or tools. So applications that are permissible and available must be used, e.g. like Microsoft Office applications. This makes things a bit more laborious, but not impossible.

Here a Visual Basic for Application (VBA) example to detect all IDs of the UI Elements of a session of the SAP GUI for Windows with SAP GUI Scripting. The result is written into a Microsoft Excel table.

The sub routine Start connects to the session and calls the recursive sub routine GetAll, which detects all IDs. The global variable gColl stores all IDs as an array of strings.
'-Begin-----------------------------------------------------------------

Option Explicit

Dim gColl() As String
Dim j As Integer

Sub GetAll(Obj As Object) '---------------------------------------------
'-
'- Recursively called sub routine to get the IDs of all UI elements
'-
'-----------------------------------------------------------------------

Dim cntObj As Integer
Dim i As Integer
Dim Child As Object

On Error Resume Next
cntObj = Obj.Children.Count()
If cntObj > 0 Then
For i = 0 To cntObj - 1
Set Child = Obj.Children.Item(CLng(i))
GetAll Child
ReDim Preserve gColl(j)
gColl(j) = CStr(Child.ID)
j = j + 1
Next
End If
On Error GoTo 0

End Sub

Sub Start() '-----------------------------------------------------------
'-
'- Sub routine to get all UI elements of the SAP GUI for Windows
'- with connection 0 and session 0
'-
'-----------------------------------------------------------------------

Dim SapGuiAuto As Object
Dim app As SAPFEWSELib.GuiApplication
Dim connection As SAPFEWSELib.GuiConnection
Dim session As SAPFEWSELib.GuiSession
Dim i As Integer

Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If

Set app = SapGuiAuto.GetScriptingEngine
If Not IsObject(app) Then
Exit Sub
End If

Set connection = app.Children(0)
If Not IsObject(connection) Then
Exit Sub
End If

If connection.DisabledByServer = True Then
Exit Sub
End If

Set session = connection.Children(0)
If Not IsObject(session) Then
Exit Sub
End If

If session.Info.IsLowSpeedConnection = True Then
Exit Sub
End If

GetAll session

For i = LBound(gColl) To UBound(gColl)
Cells(i + 1, 1) = gColl(i)
Next

End Sub

'-End-------------------------------------------------------------------

Here an example of a result:


With the access to all UI elements you can detect each information you need, e.g. like name, type, position, size, etc. On this way you can e.g. easily compare two versions of an UI, to find the differences.
10 Comments
Very useful code that I was searching for some time. Thanks for sharing.

 

Please tell me what are the references that I need to add in EXcel VBA window to get this code running?
Stefan-Schnell
Active Contributor
0 Kudos
kannannp

Hello Kannan,

you have only to reference to SAPFEWSE.OCX library.

Best regards
Stefan
qurm
Participant
Hi Stefan,

Very useful script - I made a couple of small changes to get the control Type, Name and Id in a columnar format.
      ReDim Preserve gColl(j)
gColl(j) = CStr(Child.Type) & ", " & CStr(Child.Name) & ", " & CStr(Child.ID)
j = j + 1

 
  For i = LBound(gColl) To UBound(gColl)
Cells(i + 1, 1) = Split(gColl(i), ",")(0)
Cells(i + 1, 2) = Split(gColl(i), ",")(1)
Cells(i + 1, 3) = Split(gColl(i), ",")(2)
Next

 
Stefan-Schnell
Active Contributor
0 Kudos
Thanks for sharing qurm
0 Kudos
Hello Stefan,

am kind of new with SAP scripting. I used this script, but it say "End of statement expected". Can you please tell me how to run this script correctly

Thank you and appreciate you help

Hara
Stefan-Schnell
Active Contributor
0 Kudos
Hello Hara,

please check if you copy the code completely, with no additional characters and correct spaces. The "End of statement expected" means that the statement is syntactically complete, but an additional programming element follows the element that completes the statement.

Best regards
Stefan
former_member750601
Discoverer
very userful and I will try it tommorrow
GusRomez
Discoverer
0 Kudos

This is really helpful you saved me from a lot of stress.
Thank you so much for sharing!!

JFG
Discoverer
0 Kudos

Hola qurm

Intente acomodar el codigo, pero me sale error, por favor compartir código con la mejora, gracias.

I tried to adjust the code, but I got an error, please share code with the improvement, thank you.

aabida_majeed
Participant
0 Kudos

Could you help me with the C# code for this ? 

Labels in this area