on 08-10-2015 2:31 PM
Using VBA, I've recently found out the way below to select the desired TAB (when within a sales order, for instance).
For T = 0 To 15
If Len(T) = 1 Then T = "0" & T
If SapSession.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\" & T).Text = "Sales" Then
SapSession.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\" & T).Select
Exit For
End If
Next T
I am looking now for a similar way to loop through the fields in the current active window in order to select (setfocus) on a specific field. Is it possible?
Thank you
Hello Levy,
welcome in the Scripting Language forum.
Here a solution to scan the entire user screen and to get all elements:
'-Begin-----------------------------------------------------------------
Sub ScanFields(Area As Object, Application As SAPFEWSELib.GuiApplication)
Dim Children As Object
Dim i As Integer
Dim Obj As Object
Dim ObjChildren As Object
Dim NextArea As Object
Set Children = Area.Children()
For i = 0 To Children.Count() - 1
Set Obj = Children(CInt(i))
'If Obj.Type = "GuiTextField" Then
'If Obj.Name = "MyField" Then
'Obj.SetFocus
Debug.Print Obj.Name & " " & Obj.Type & " " & Obj.Text
'End If
'End If
If Obj.ContainerType() = True Then
Set ObjChildren = Obj.Children()
If ObjChildren.Count() > 0 Then
Set NextArea = Application.findByID(Obj.ID)
ScanFields NextArea, Application
Set NextArea = Nothing
End If
Set ObjChildren = Nothig
End If
Set Obj = Nothing
Next
Set Children = Nothing
End Sub
'---------------------------------------------------------------------
Sub Test()
Dim SapGuiAuto As Object
Dim Application As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim Session As SAPFEWSELib.GuiSession
Dim UserArea As SAPFEWSELib.GuiUserArea
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set Application = SapGuiAuto.GetScriptingEngine()
If Not IsObject(Application) Then
Exit Sub
End If
Set Connection = Application.Connections(0)
If Not IsObject(Connection) Then
Exit Sub
End If
Set Session = Connection.Sessions(0)
If Not IsObject(Session) Then
Exit Sub
End If
'-Get the user area and scan it recursively---------------------------
Set UserArea = Session.findByID("wnd[0]/usr")
ScanFields UserArea, Application
Set UserArea = Nothing
End Sub
'-End-------------------------------------------------------------------
I commented the lines in the sub routine ScanFields to select your specific field and to set the focus.
It is necessary to check if an object is a container and to scan the objects in that case recursively
Let us know your results.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello klambe,
the code doesn't ignore GridViews. A GridView is one object on the user screen. It contains no objects which can be determined with this method. If you need detail information about the content of the GridView, it is necessary to use the methods and properties of the GuiGridView object.
Best regards
Stefan
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.