Formatted
Formatted

Reputation: 11

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

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

Upvotes: 1

Views: 12549

Answers (2)

user4114827
user4114827

Reputation: 11

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.

Upvotes: 1

Jan W Roosch
Jan W Roosch

Reputation: 11

if still hang problems after advice by Edgar M ( correcting connection to SAPCon ),
try adding a little delay before Set session.. (or before which ever line where the hanging occurs) .. so in this case SAPCon has enough time to complete (within the run environment) before code continuation (related to ever faster getting pc's?).
So like:

..
Set SAPCon = SAPApp.Children(0)
WScript.Sleep 200
Set session = SAPCon.Children(0)

After this, the random hangs seemed over.
Best, JanW

Upvotes: 0

Related Questions