Reputation: 21
I'm creating a script and I need to interact with the second sap tab (in red). When I generate a log using the second screen, it continues playing on the first screen (in green). I would like to interact with several tabs at the same time. What do I need to change in the code for this?
Below is a code example obtained by reproducing in the second tab
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "va03"
session.findById("wnd[0]").sendVKey 0
Upvotes: 0
Views: 688
Reputation: 21
Maybe you can use this way of cycling through different sessions:
' Cycle through the open SAP GUI sessions and check which is in the same
' system running the matching transaction
For il = 0 To application.Connections.Count - 1
Set W_conn = application.Connections(il + 0)
For it = 0 To W_conn.Sessions.Count - 1
Set W_Sess = W_conn.Sessions(it + 0)
If W_Sess.Info.SystemName = "NPL" Then
Set objConn = W_conn
Set objSess = W_Sess
Exit For
End If
Next
Next
For more information about the properties and the methods, look at the documentation:
Connections
(alias: Children
) of type GuiComponentCollection
Sessions
(alias: Children
) of type GuiComponentCollection
Info
of type GuiSessionInfo
Item
, property Count
(NB: indicating application.Connections(x)
is the same as application.Connections.Item(x)
SystemName
, Client
, User
, Language
, etc.Upvotes: 2