Skip to Content
0
Former Member
Sep 19, 2014 at 12:37 PM

VBA to SAP Logon - logged in fine, nothing happens after

263 Views

Hello everyone,

I have been trying to start a new SAP session from scratch by calling its API from the Excel VBA. Thanks to this forums I've managed to start a new SAP window, enter my credentials and successfully log in to the system. However, I can only think it is successful because when the credentials are correct, the window disappears and nothing happens after that. If I enter the incorrect credentials, it won't let me through which I understand as a sign that the session is properly connected to the database.

Is there any way to force the SAP GUI keep open after I log in? Is it normal that it disappears?

The code I use to prompt the logon window:

If SapGuiApp Is Nothing Then
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If

If Conn Is Nothing Then
Set Conn = SapGuiApp.OpenConnectionByConnectionString("mycompanyserver.com", True, False)
End If

If SAPSesi Is Nothing Then
Set SAPSesi = Conn.Children(0)
End If

After that I want to be able to run the macro the following way:

With SAPSesi

.findById("wnd[0]/tbar[0]/btn[12]").press

.findById("wnd[0]/tbar[0]/okcd").Text = "TRANSACTION"

.findById("wnd[0]/tbar[0]/btn[0]").press

etc.

Thank you!

Krzysiek