I'm trying to run a basic code I've found numerous places on here and elsewhere which should open SAP, input a command, and execute.
I've gone as far as SAP opening through VBA but I get runtime error 614 at line Set Connection = Appl.Openconnection("1) PRD", True).Children(0)
below, in regard to setting the "session" as shown.
Run-Time Error 614: The enumerator of the collection cannot find en element with the specified index
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
return in the immediate window if you put it beforeSet session = Connection.Children(0)
? – Nacorid