Skip to content

Instantly share code, notes, and snippets.

@kerrypnx
Created April 26, 2020 02:41
Show Gist options
  • Save kerrypnx/e488f15a92e7ee22d6c9ef715c451210 to your computer and use it in GitHub Desktop.
Save kerrypnx/e488f15a92e7ee22d6c9ef715c451210 to your computer and use it in GitHub Desktop.
SAPOpenSessionFromLogon
Sub SAPOpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Dim Path
Path = "'C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe' /LSXML_File='C:\sap\SAPUILandscape.xml'"
SAPPath = Replace(Path, "'", Chr(34))
Shell (SAPPath)
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set connection = Applic.OpenConnection("S/4 HANA PROD (E1P)", False) '<=== here you need to fillin your connection description
Set session = connection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "800" ' 集团
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "RPAPSS" '账号
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Rpapss@123" '密码
session.findById("wnd[0]").sendVKey 0
'Rem Do something: Either fill out the login screen
'Rem or in case of Single-Sign-On start a transaction.
' session.SendCommand ("/nbibs")
' MsgBox "Waiting..."
' 'Rem Shutdown the connection
' Set session = Nothing
' connection.CloseSession ("ses[0]")
' Set connection = Nothing
' Set sap = Nothing
' MsgBox "Done"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment