title: How to choose specific SAP GUI session?
body: <p>I am trying to run an Excel VBA code which uses SAP GUI Scripting.</p>
  <p>I have some open sessions in Sap and using two systems &quot;F6P&quot; and &quot;FVP&quot; at the same time.</p>
  <p>How do I run on one of the &quot;FVP&quot; sessions?<br />
  You can see below there are two session open<br />
  One is F6P SAP box and the other is FVP SAP box.<br />
  <a href="https://i.stack.imgur.com/Y9wku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y9wku.png" alt="enter image description here" /></a></p>
  <pre class="lang-vb prettyprint-override"><code>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(&quot;SAPGUI&quot;)
          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, &quot;on&quot;
          WScript.ConnectObject App, &quot;on&quot;
          Set Session = Application.ActiveSession
      End If
  End Sub
  
  Sub tcode()
      Session.findById(&quot;wnd[0]&quot;).maximize
      Session.findById(&quot;wnd[0]/tbar[0]/okcd&quot;).Text = &quot;/n/sapapo/bopin&quot;
      Session.findById(&quot;wnd[0]&quot;).sendVKey 0
  End Sub  
  </code></pre>