It appears that I am running constantly in a problem that shouldn't exist as googleing it assumes that the code works. I try to simply run a SAP-transaction from Excel with VBA. I am logged into SAP, ready to issue the transaction. So the code connects to the GUI of SAP via the scripting engine and tries to grab the open session but fails:
Sub MVE
Dim oSapGui As Object
Dim oApp As SAPFEWSELib.GuiApplication
Dim oConn As SAPFEWSELib.GuiConnection
Dim oSession As SAPFEWSELib.GuiSession
'Get the currently running SAP GUI
Set oSapGui = GetObject("SAPGUI")
Set oApp = oSapGui.GetScriptingEngine
Debug.Print "oApp.Children.Count: " + Str(oApp.Children.Count) 'for debugging
'Get the first system that is currently connected
Set oConn = oApp.Children(0)
Debug.Print "oConn.Children.Count: " + Str(oConn.Children.Count) 'for debugging
'Get the first session (window) on that connection
Set oSession = oConn.Children(0) '<-- Fails. There are no child objects, i.e. no sessions available
End Sub
The debugging output is:
oApp.Children.Count: 1
oConn.Children.Count: 0
and the corresponding error is obviously
Runtime error '614':
The enumerator of the collection cannot find an element with the specified index.
The code is stripped to the absolute necessary and many posts on the net suggest that it should work, but it doesn't (e.g. this on stackoverflow or this, this, or this in the SAP forums ). Scripting is enabled in both, SAP and Excel/VBA, as other posts identified as root cause.