[英]Trouble Connecting to SAP Through VBA in Excel Error 614
我正在尝试运行一个基本代码,我在这里和其他地方发现了许多应该打开 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
请检查您的 SAP 连接的名称。 根据下面的示例,相应的命令如下所示:
...
Set Connection = Appl.openconnection("DAL_ EHP5")
Set session = Connection.Children(0)
...
此外,您可能需要先登录 SAP。
例如:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = Mandant
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = Name
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = PW
session.findById("wnd[0]").sendVKey 0
问候, ScriptMan
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.