Reputation: 27
I'm trying to execute a SAP GUI script with VBA but it is showing the following error
The enumeration of the collection cannot find en element with the specified index
I've tried some solutions, but nothing has worked so far. Any idea?
The button to record script in SAP GUI, went completely blank, out of nowhere.
Upvotes: 1
Views: 2254
Reputation: 162
I use the code below, you just need to change the OpenConnection command to the "SAP Program" that i'll use, in this case i'm using the R/3 PCL nuevo
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbHide
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
T0 = Timer
Do
Delay = Timer - T0
Loop Until Delay > 1 'tempo pra abrir o sap
Loop
Set WSHShell = Nothing
If Not IsObject(appl) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set appl = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = appl.OpenConnection("R/3 PCL nuevo", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject appl, "on"
End If
Upvotes: 1