SAP GUI脚本错误,“集合的枚举器找不到具有指定索引的元素”。

几个星期前,我通过SAP内置的GUI脚本function生成了一个脚本,然后把vba放在一个excel文档中,并将其附加到一个button上。

这工作完全罚款几个星期,但是现在当我按下button我得到这个错误: "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打开,我login,并在代码段中的所有代码是由SAP gui脚本生成的。

我尝试了一些我在网上看到的解决scheme(比如在我的sap安装文件夹中添加一些ocx文件到我的excel插件中),但似乎没有任何工作。

我想知道是否有人在这里遇到类似的问题,并知道我如何能成功地在我的vba中打开一个SAP会话。

编辑评论:

当我检查连接对象时,这是我所看到的。 它看起来像儿童的长度是0。

调试器视图

我认为我安装的其他东西(甚至可能是我公司的更新脚本)弄糟了安装SAP时安装的vba支持。

重新安装SAPlogin应用程序解决了我的问题

(如果有人给出更好的理由为什么发生这种事,我会接受这个答案)

我知道这是很老的,但可能可以帮助别人。 我不知道这个原因,突然发现我的脚本有问题。 我logging了一个新的操作,看看SAP会为这些操作写什么(因为那部分代码是连接的标准)。 相同的代码,同样的问题。

修复(或至less暂时):更改正在search的孩子的号码。 前面的代码:

 *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* 

执行发生在第二个会话,如果你改变这个,也必须改变以前的代码行。

希望能帮助到你!