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.
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…