on 04-03-2024 11:59 AM
Hi,
I am trying to retrieve my SAP session with the following VBA code
If Not IsObject(app) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set app = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = app.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
I get an error on the following line
Set session = Connection.Children(0)
Error message: The enumerator of the collection cannot find an element with the specified index.
User scripting is enabled on my machine. And I open SAP and login with my account before executing code above.
Can you please share your ideas on a resolution?
Hi,
apart from the question whether you have activated SAP GUI Scripting at all (see the other answers) I wonder whether you have a session at all at the time you run your script.
This command
Set session = Connection.Children(0)
can only work if you have opened a connection from SAP Logon.
SAP Logon itself does not have a scripting API - the API is basically only available for the main windows belonging to a connection and their children. Connection is the object which contains all available connections - if you have none, you will get the respective error.
If the later is the problem I advise that you first check the scripting API documentation.
Best regards,
Frank
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
74 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.