gpt4 book ai didi

excel - SAP GUI 脚本错误, "The Enumerator of the collection cannot find an element with the specified index."

转载 作者:行者123 更新时间:2023-12-04 17:59:55 27 4
gpt4 key购买 nike

几周前,我通过 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 session 。

编辑评论:

当我检查连接对象时,这就是我所看到的。看起来 child 长度为0。

Debugger View

最佳答案

遇到了同样的问题并找到了这个线程,所以我用对我有用的解决方案来恢复它:

脚本可能已经失效。
sapgui/user_scripting 必须设置为 true

关于excel - SAP GUI 脚本错误, "The Enumerator of the collection cannot find an element with the specified index.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com