cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Logon with VBA

Former Member
0 Kudos

Good morning, everybody!

I've been looking for the solution in the last days but I really have not managed to succeed:

I am trying to make a vba code to:

1-log into SAP,

2-run some transactions

3-export to excel.

But even the "log into SAP" part is not OK!

I tried several codes, the one below OPENS the SAP logon screen, but does not fill in any fields. I Used CreateObject("Sapgui.ScriptingCtrl.1"):

Sub Entrar_SAP()

If Not IsObject(SAPguiApp) Then

Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")

End If

If Not IsObject(Connection) Then

Set Connection = SAPguiApp.OpenConnection("xxxxxxx)", True)

End If

If Not IsObject(session) Then

Set session = Connection.Children(0)

End If

session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"

session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "pass"

session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"

session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2

session.findById("wnd[0]").sendVKey 0

ANother one, with CreateObject("SAP.Functions"), showed:

"RFC error received. No RFC authorization for function module RFC PING"

the code is:

'Declaration

Dim objBAPIControl As Object 'Function Control (Collective object)

Dim sapConnection As Object 'Connection object

Set objBAPIControl = CreateObject("SAP.Functions")

Set sapConnection = objBAPIControl.Connection

sapConnection.Client = "xxxxx"

sapConnection.User = "xxxxxx"

sapConnection.Language = "PT"

sapConnection.hostname = "xxxxx"

sapConnection.Password = "xxxxxxxx" 'Fake password

sapConnection.SystemNumber = "4"

sapConnection.System = "xxxxxx)"

sapConnection.Logon

If sapConnection.Logon(1, True) <> True Then

MsgBox "No connection to R/3!"

Exit Sub 'End program

End If

Can someone please help me?

Thanks!!

Accepted Solutions (1)

Accepted Solutions (1)

Sriram2009
Active Contributor
0 Kudos

Hi Eduardo


1-log into SAP,

2-run some transactions

You can create the simple .BAT or .CMD on Windows OS.

refer the help in start sapshcut /?

Syntax-

Start sapshcut -system=SID -client=xxx   -desc= " description of System" - user= USER ID -pw=password -maxgui -command= "transaction code"


3-export to excel.

For this you can create the Z custom program export the data to excel file format as output .

BR

SS

Former Member
0 Kudos

THanks for answering! Unfortunately, the bat does not work. I've copied and paste exactly as you. What can i do?

Sriram2009
Active Contributor
0 Kudos

Hi

With same script we are using in our environment.

From the command prompt you can type " start sapshcut /? " you can find the help menu with syntax and switches settings

For Example

SID = DEV 

System description - Development system

Client = 100

User id = Test1

password= welcome

Start sapshcut -system=dev -client=100   -desc= "Development system " - user=test1  -pw=welcome -maxgui -command=St03


Refer the SAP note 103019 - SAPshortcut: Program parameters


Regards

SS

Former Member
0 Kudos

Thanks again for answering! The problem is that it is not recognizing username and password! I've tried with " "  but has not worked either! It keeps on opening the log on screen with my PC username (different from SAP name). Do you have any suggestions?? Also i've tried opening the link but i have no access to that page (need login).

Sriram2009
Active Contributor
0 Kudos

Hi

1. Are you trying in which OS?(Windows 7 or 8)? SAPGUI version & patch level?

2. Just open the command prompt type the command manually and the check the result.

3. You can refer the snapshot of help menu with syntax "Start Sapshcut /?"

BR

SS

Former Member
0 Kudos

Hello again! Thanks! i used the code below and it worked. for some reason in sap version 730 yours was not working.

Now that I can enter in a transaction, my next move is to run the transactions and report to Excel kkk. The problem is that I dont have permission in my company to use ABAP transactions.

By the way, do you know a way to log in with command without opening the "are you sure you want to open the file" screen?

Start sapshcut -sysname="Customer PRD" -client=100 -user=CONUSER -pw=PASS -language=EN -type=Transaction -command=SESSION_MANAGER

Sriram2009
Active Contributor
0 Kudos

Hi

I am not sure about the ABAP program, After the password you have to use the syntax

"Start sapshcut -sysname="Customer PRD" -client=100 -user=CONUSER -pw=PASS -language=EN -maxgui -command=St03"

BR

SS

Former Member
0 Kudos

Hello! Thanks for answering! I mean that when i press enter in CMD file i want the transaction to open directly. Now i receive a Windows alert "Do you want to open the file? SAP(...)". Is there a way to make it not appear?

Att,

Eduardo

Sriram2009
Active Contributor
0 Kudos

Hi

Could you share the screen shot?

BR

SS

Former Member
0 Kudos
Sriram2009
Active Contributor
0 Kudos

Hi

Its a just warning message while opening the command. refer the your tube video to disable the pop-up or just uncheck the option on the same screen

How to disable open file security warning on start-up Including Internet Download Manager(IDM) ...HD...

BR

SS

Answers (1)

Answers (1)

divyanshu_srivastava3
Active Contributor
0 Kudos

1-log into SAP,

2-run some transactions

3-export to excel.

Do you know about SECAT ?

May be that can help and save your efforts you are putting into VBA ?

Regards,

Former Member
0 Kudos

Hello, Divyanshu! Thanks for answering!

I dont know anything about that. I've just did a quick research on the web and it is related to ABAP programming, right?

I dont have access to ABAP transactions in the company I work for (Despite the fact that i wanted to)

However, i do know a lot about VBA, thats why i intended to do that way.

Regards,