我使用下面的代码,您只需将OpenConnection命令更改为我将使用的“SAP程序”,在本例中,我使用的是R/3 PCL nuevo
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbHide
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
T0 = Timer
Do
Delay = Timer - T0
Loop Until Delay > 1 'tempo pra abrir o sap
Loop
Set WSHShell = Nothing
If Not IsObject(appl) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set appl = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = appl.OpenConnection("R/3 PCL nuevo", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject appl, "on"
End If