on 12-16-2015 7:09 PM
Hi, guys.
I am trying to open the SAP Logon By macro, but the program was until the red line below. The VBA showed the error message "The enumerator of the collection cannot find en element with thye specified index"
Do you know what's happening?
Sub SAP_OpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Shell ("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewcp.exe")
Set SapGui = GetObject("SAPGUI")
Rem Create the GuiApplication object
Set Applic = SapGui.GetScriptingEngine
Rem Open a connection
Set connection = Applic.OpenConnection("QLA - ECC Project One Quality System", True) '<=== here you need to fillin your connection description
Set session = connection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "120"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "MASOUZA"
session.findById("wnd[0]").sendVKey 0
Rem Do something: Either fill out the login screen
Rem or in case of Single-Sign-On start a transaction.
session.SendCommand ("/nbibs")
MsgBox "Waiting..."
Rem Shutdown the connection
Set session = Nothing
connection.CloseSession ("ses[0]")
Set connection = Nothing
Set sap = Nothing
MsgBox "Done"
End Sub
Hello Fulvio,
your VBA code looks very good. All I changed I marked red. I start saplogon.exe and not sapfewcp.exe, because in the saplogon.exe is the SAPGUI object. And I wait with a loop until the saplogon window is available and therewith the object SAPGUI.
Sub SAP_OpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Dim WSHShell
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
Set connection = Applic.OpenConnection("QLA - ECC Project One Quality System", True)
Set session = connection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "120"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "MASOUZA"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "secret"
session.findById("wnd[0]").sendVKey 0
session.SendCommand ("/nBIBS")
MsgBox "Waiting..."
Set session = Nothing
connection.CloseSession ("ses[0]")
Set connection = Nothing
Set sap = Nothing
MsgBox "Done"
End Sub
Let us know your results.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.