Object required error on Set session = Connection.Children(0)

Formatted picture Formatted · Jun 10, 2014 · Viewed 7.9k times · Source

I'm trying to start a SAP GUI script and to change some of the variables of the VBA code.

I get

Runtime error '424' Object required

on Set session = Connection.Children(0)

Public Sub SimpleSAPExport()
Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
Set session = Connection.Children(0) 'Get the first session (window) on that connection

'  Start the transaction to view a table
session.StartTransaction "SE16"
end sub

Answer

user4114827 picture user4114827 · Oct 6, 2014

You are getting the error message because the object Connection doesn't exist, just change this object to the actual object SAPCon and execute your code. I was facing same issue and it was solved changing this object:

Set SapGuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

Best,

Edgar M.