1
votes

I am trying to run an Excel VBA code which uses SAP GUI Scripting.

I have some open sessions in Sap and using two systems "F6P" and "FVP" at the same time.

How do I run on one of the "FVP" sessions?
You can see below there are two session open
One is F6P SAP box and the other is FVP SAP box.
enter image description here

Option Explicit
Public SapGui, App, Connection, Session, SapGuiAuto, WScript

Sub Overconfirmation()
    Call SAP
    Call tcode
    End
    Sub SAP()
    If Not IsObject(App) Then
        Set SapGuiAuto = GetObject("SAPGUI")
        Set App = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
        Set Connection = App.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 App, "on"
        Set Session = Application.ActiveSession
    End If
End Sub

Sub tcode()
    Session.findById("wnd[0]").maximize
    Session.findById("wnd[0]/tbar[0]/okcd").Text = "/n/sapapo/bopin"
    Session.findById("wnd[0]").sendVKey 0
End Sub  
1
please provide your working code.hongsy
I edited your question because SAPscript is completely different from SAP GUI Scripting, and not related at all. You use the latter one.Sandra Rossi
I have updated my request with more data.. thanks in advance.Zounds

1 Answers

2
votes

The ID of the SAP system is defined in the property SystemName of the object GuiSessionInfo, which itself is the property Info of the object GuiSession. You may access all the existing sessions with this code:

For connNr = 0 To Application.Children.Length - 1
  Set conn = Application.Children.ElementAt(connNr)
  For sessNr = 0 to conn.Children.Length - 1
    Set sess = conn.Children.ElementAt(sessNr)
    If sess.Busy = False Then
      ' Test Busy because property Info is blocked when the session runs something
      If sess.Info.SystemName = "FVP" Then
        ' Do whatever you want with session sess
      End If
    End If
  Next
Next