Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Vba sap gui scripting choose specific session

$
0
0

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 to 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

   enter code here
Option Explicit
    Public SapGui, App, Connection, Session, SapGuiAuto, WScriptSub 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  

Thank you.

enter image description here


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>