cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

holger_khn
Contributor
0 Kudos

Hello Krystof. Once the procedure (macro) is done all objects got cleared. Fillin a messagebox before your code end:

msgbox "Wait to check session Frame..."

Best regards,

Holger

Former Member
0 Kudos

Hi Holger,

Thank you for such a quick response.

I added the msgbox but it didn't help. I have never actually run the macro all the way down at once, I was always going line by line. The logon window appears on this line:

Set Conn = SapGuiApp.OpenConnectionByConnectionString("mycompanyserver.com", True, False)

then I run the procedure down to Set SAPSesi = Conn.Children(0), enter my credentials and press Enter. The SAP window disappears, but procedure is "running", being stopped at the last line of it.

I know the objects are not cleared because 'If SapGuiApp Is Nothing Then' tests for false.

The screenshot was taken right before I press Enter, after that the SAP closes and macro stays at MsgBox line.

Can this be because I use the old SAP interface?

Regards,

Krzysiek

holger_khn
Contributor
0 Kudos

Hello.

Call a Transaction when Session is created:


SapSesi.SendCommand("/nbibs")

Hope this works.

You can check this as well in SAP Scripting Help: CreateObject

Former Member
0 Kudos

Still no luck. I get the following error for using SendCommand or any other piece of code that tries to connect with SAP GUI:

I have a feeling that there is no connection with SAP GUI at all or there is one up until I log in.

Two more things that may be important:

1) SAP is on Citrix environment

2) I use the address from "Message Server" column in SAP Logon Pad as the server address in OpenConnectionByConnectionString method, not sure if that's the correct one

Thank you for your help.

holger_khn
Contributor
0 Kudos

May you should try to adopt to open SAP session if this will work.