cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

[SAP Script - Visual Basic] Log in.

Former Member
0 Likes
3,343

Dear all,

I have been using the SAP application for two years now. And this is my first time asking a question on SAP.com. I just found out the Script feature of SAP. I find this feature quite cool and it can be combined with Visual Basic of Excel. It can help me reduce my time working with SAP.

Here is my SAP:

I started by creating a command to log in to SAP automatically using Visual Basic - Excel. I refer to how to do it here: Connect to SAP via Excel VBA - Simple Excel VBA

But it seems that the version of SAP I'm using is different from the one on the tutorial website. So I was stuck at login panel. Specifically, it didn't run automatically and it stopped at the login panel (picture below): untitled.png

After investigating, I understand that my command is stuck because my login panel is not the same as in the instructions. After I type my user and password, another log in panel is show up. And this login panel is the same as in instruction.

So, could you please help me to fix this ? What should I do now ?

Dim Appl As Object
Dim Connection As Object
Dim session As Object
Dim WshShell As Object
Dim SapGui As Object

'Of course change for your file directory
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", 4
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 Appl = SapGui.GetScriptingEngine
Set Connection = Appl.Openconnection("test", _
    True)
Set session = Connection.Children(0)

'if You need to pass username and password
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "200"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Badboy"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "password"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

Accepted Solutions (0)

Answers (0)