本文介绍了SAP GUI 脚本错误,“集合的枚举器找不到具有指定索引的元素."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周前,我通过 SAP 的内置 GUI 脚本功能生成了一个脚本,然后将 vba 放在一个 excel 文档中并将其附加到一个按钮上.

A few weeks ago I generated a script via SAP's built in GUI scripting functionality, and then put the vba in an excel document and attached it to a button.

这几个星期都很好,但是现在当我按下按钮时,我收到了这个错误:集合的枚举器找不到具有指定索引的元素."Set session = Connection.Children(0) 行上这是一段代码

this worked perfectly fine for few weeks, however now when I press the button I get this error:"The enumerator of the collection cannot find en element with the specified index." on the line that says Set session = Connection.Children(0)Here is a snippet of code

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 脚本生成.

I have SAP open and I'm logged in, and all of the code in the snippet was generated by SAP gui scripting.

我尝试了一些我在网上看到的解决方案(例如将我的 sap 安装文件夹中的一些 ocx 文件添加到我的 excel 插件中),但似乎没有任何效果.

I tried a few solutions I saw online (like adding some ocx files that were in my sap install folder into my excel addons) but nothing seems to be working.

我想知道这里是否有人遇到过类似的问题,并且知道如何在我的 vba 中成功打开 SAP 会话.

I was wondering if anyone on here has ran into a similiar problem, and know how I can successfully open an SAP session in my vba.

从评论中

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

When I inspect the connection object this is what I see. It looks like Children length is 0.

推荐答案

我认为我安装的其他东西(或者甚至我公司的更新脚本)搞砸了安装 SAP 时安装的 vba 支持.

I think something else I installed (or maybe even my company's updating scripts), messed up the vba support that is installed when you install SAP.

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

Re installing the SAP Logon application fixed my issue

(如果其他人给出了更好的理由来解释为什么会发生这种情况,我会接受这个答案)

(if someone else gives a better reason to WHY this happened, I'll accept that answer)

这篇关于SAP GUI 脚本错误,“集合的枚举器找不到具有指定索引的元素."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:02