使用 VBA 执行 SAP Scritping 时出错

Error in execution of SAP Scritping with VBA

我正在尝试使用 vba 执行 SAP 脚本,但它显示以下错误 "The enumeration of the collection cannot find en element with the specified index"

我已经尝试了一些解决方案,但到目前为止没有任何效果? 在 sap 中录制脚本的按钮,完全空白,不知从何而来。

我使用下面的代码,您只需将 OpenConnection 命令更改为我将使用的 "SAP Program",在本例中我使用的是 R/3 PCL新

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