0

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) a specific field. Is it possible?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
AndroidDev
  • 831
  • 5
  • 17
  • 36

1 Answers1

0

I found this piece of code at SAP community site and it works fine.

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

        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
        End If
   Next i

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
AndroidDev
  • 831
  • 5
  • 17
  • 36