/ / Jak znaleźć pożądane pole w SAPGUI przy użyciu VBA - vba, sap

Jak znaleźć pożądane pole w SAPGUI przy użyciu VBA - vba, sap

Niedawno dowiedziałem się, jak wybrać poniżej żądaną tablicę TAB (na przykład w przypadku zamówienia sprzedaży).

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

Teraz szukam podobnego sposobu, aby przechodzić przez pola w bieżącym aktywnym oknie, aby wybrać (setfocus) w określonym polu. Czy to możliwe?

Odpowiedzi:

0 dla odpowiedzi № 1

Znalazłem ten fragment kodu na stronie społeczności SAP i działa dobrze.

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