SAP GUI 脚本错误,"The Enumerator of the collection cannot find an element with the specified index."
SAP GUI Scripting Error, "The Enumerator of the collection cannot find an element with the specified index."
几周前,我通过 SAP 内置的 GUI 脚本功能生成了一个脚本,然后将 vba 放入 excel 文档并将其附加到一个按钮。
这几个星期都工作得很好,但是现在当我按下按钮时我得到这个错误:
"The enumerator of the collection cannot find en element with the specified index."
在 Set session = Connection.Children(0)
行
这是一段代码
If Not IsObject(Sap_Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Sap_Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Sap_Application.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0) 'This is the line that causes the error
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Sap_Application, "on"
End If
我打开了 SAP 并登录了,片段中的所有代码都是由 SAP gui 脚本生成的。
我尝试了一些我在网上看到的解决方案(比如将我的 sap 安装文件夹中的一些 ocx 文件添加到我的 excel 插件中)但似乎没有任何效果。
我想知道这里是否有人 运行 遇到过类似的问题,并且知道如何在我的 vba.
中成功打开 SAP 会话
根据评论编辑:
当我检查连接对象时,这就是我所看到的。看起来 Children 的长度是 0。
我认为我安装的其他东西(或者甚至可能是我公司的更新脚本)扰乱了安装 SAP 时安装的 vba 支持。
重新安装 SAP Logon 应用程序解决了我的问题
(如果其他人对发生这种情况的原因给出了更好的理由,我会接受这个答案)
我知道它很旧,但可能会对其他人有所帮助。
我不知道这是什么原因,我的脚本突然开始出现问题。我记录了一个新的操作,看看 SAP 会为这些操作编写什么(因为那部分代码是连接的标准代码)。
同样的代码,同样的问题。
修复(或至少是暂时的):
更改正在搜索的 child 的编号。
上一个代码:
*Set Connection = Sap_Application.Children(0)*
新代码:
*Set Connection = Sap_Application.Children(1)*
不确定有什么区别,我知道如果您也更改此行中的数字:
*Set session = Connection.Children(0) 'This is the line that causes the error*
在第二个session中执行,如果改了这一个,也得改之前的那行代码。
希望对您有所帮助!
遇到了同样的问题并找到了这个线程,所以我用对我有用的解决方案恢复它:
脚本可能已停用。
sapgui/user_scripting 必须设置为 true
请检查是否启用了脚本。当您启用 client-level 脚本时,如果服务器重新启动,它会自动重置。
与生产环境相比,您在沙盒或演示系统上遇到此问题的频率可能更高:-)
几周前,我通过 SAP 内置的 GUI 脚本功能生成了一个脚本,然后将 vba 放入 excel 文档并将其附加到一个按钮。
这几个星期都工作得很好,但是现在当我按下按钮时我得到这个错误:
"The enumerator of the collection cannot find en element with the specified index."
在 Set session = Connection.Children(0)
行
这是一段代码
If Not IsObject(Sap_Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Sap_Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Sap_Application.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0) 'This is the line that causes the error
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Sap_Application, "on"
End If
我打开了 SAP 并登录了,片段中的所有代码都是由 SAP gui 脚本生成的。
我尝试了一些我在网上看到的解决方案(比如将我的 sap 安装文件夹中的一些 ocx 文件添加到我的 excel 插件中)但似乎没有任何效果。
我想知道这里是否有人 运行 遇到过类似的问题,并且知道如何在我的 vba.
中成功打开 SAP 会话根据评论编辑:
当我检查连接对象时,这就是我所看到的。看起来 Children 的长度是 0。
我认为我安装的其他东西(或者甚至可能是我公司的更新脚本)扰乱了安装 SAP 时安装的 vba 支持。
重新安装 SAP Logon 应用程序解决了我的问题
(如果其他人对发生这种情况的原因给出了更好的理由,我会接受这个答案)
我知道它很旧,但可能会对其他人有所帮助。 我不知道这是什么原因,我的脚本突然开始出现问题。我记录了一个新的操作,看看 SAP 会为这些操作编写什么(因为那部分代码是连接的标准代码)。 同样的代码,同样的问题。
修复(或至少是暂时的): 更改正在搜索的 child 的编号。 上一个代码:
*Set Connection = Sap_Application.Children(0)*
新代码:
*Set Connection = Sap_Application.Children(1)*
不确定有什么区别,我知道如果您也更改此行中的数字:
*Set session = Connection.Children(0) 'This is the line that causes the error*
在第二个session中执行,如果改了这一个,也得改之前的那行代码。
希望对您有所帮助!
遇到了同样的问题并找到了这个线程,所以我用对我有用的解决方案恢复它:
脚本可能已停用。 sapgui/user_scripting 必须设置为 true
请检查是否启用了脚本。当您启用 client-level 脚本时,如果服务器重新启动,它会自动重置。 与生产环境相比,您在沙盒或演示系统上遇到此问题的频率可能更高:-)