cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble Connecting to SAP using VBA

former_member606126
Discoverer
0 Kudos

PLEASE HELP

I am trying to open a connection in Sap using a macro in vba. The macro opens a new connection, but runs into the error "The enumerator of the collection cannot find en element with the specified index" while processing....

Set session = Connection.Children(0)

I have looked everywhere for people encountering the same error, and have not found a solution. This is basically my last resort. My code is posted below....

My ultimate goal is to use session.findbyId to extract commands from the SAP statusbar, but I am failing to properly define session...

'----------- Macro

Sub Logontrial()

Dim SAPGUIAuto As Object
Dim App As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim session As SAPFEWSELib.GuiSession


Set session = Nothing
Set Connection = Nothing


Set SAPGUIAuto = GetObject("SAPGUI")
Set App = SAPGUIAuto.GetScriptingEngine

Application.Wait (Now + TimeValue("00:00:05"))

Set Connection = App.OpenConnection("P81: Produktion GS")
Application.Wait (Now + TimeValue("00:00:05"))

Set Connection = App.Children(0)

Set session = Connection.Children(0)

End Sub

This is a screenshot of my watched when in debugging...

Accepted Solutions (0)

Answers (0)