【发布时间】:2020-10-20 21:41:29
【问题描述】:
我正在尝试运行一个基本代码,我在这里和其他地方找到了很多地方,这些地方应该打开 SAP、输入命令并执行。
我已经通过 VBA 打开 SAP,但我在下面的行 Set Connection = Appl.Openconnection("1) PRD", True).Children(0) 收到运行时错误 614,关于设置“会话”,如图所示。
运行时错误 614:集合的枚举器找不到具有指定索引的元素
Private Sub CommandButton1_Click()
Dim SapGui As Object
Dim Connection As Object
Dim Appl As Object
Dim session As Object
Dim WshShell As Object
'Of course change for your file directory
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", 4
Set WshShell = CreateObject("WScript.Shell")
Do Until WshShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WshShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
Set Connection = Appl.Openconnection("1) PRD", True).Children(0)
Set session = Connection.Children(0)
session.findById("wnd[0]").Maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "cv03n"
session.findById("wnd[0]").sendVKey 0 'ENTER
'and there goes your code in SAP
End Sub
【问题讨论】:
-
如果你把
Debug.Print Connection.Children.Count放在Set session = Connection.Children(0)之前,它会在即时窗口中返回什么?