on 02-27-2007 12:29 PM
Hi,
I've been that's possible to generate a .vbs file from SAPGUI that can automate SAPGUI actions. The generated code is Visual Basic Script.
My question is if it's possible to translate this code to the regular Visual Basic, because our application is not an script. Excuse me if this is a stupid question but I'm a complete newbie in this environment.
Is there any code sample anywhere ?
Regards,
Joan
Hi,
If it can help you, I just used this VB.NET code to create a new SAP Gui session and automate the login. If scripting is enable on your servers you can use method 1 if not, use method 2 by sending the exact key sequence you want.
=============METHOD 1 with scripting enabled ==============
'====Declare objects
Dim application As Object
Dim SapGui As Object
Dim connection As Object
Dim session As Object
'===Activate SAP logon pad engine
application = CreateObject("Sapgui.ScriptingCtrl.1")
'===Initiate one of the predefined SAPlogon pad connection
SapGui = GetObject("SAPGUI")
application = SapGui.GetScriptingEngine
connection = application.OpenConnection("SAPlogon pad entry",True)
Session = connection.children(0)
'===Fill in the logon screen fields
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "username"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "psw"
'===Send enter
session.findById("wnd[0]").sendVKey(0)
=============METHOD 2 with scripting disabled ==============
'====Declare objects
Dim application As Object
Dim SapGui As Object
Dim connection As Object
Dim ins As SendKeys
'===Activate SAP logon pad engine
application = CreateObject("Sapgui.ScriptingCtrl.1")
'===Initiate one of the predefined SAPlogon pad connection
SapGui = GetObject("SAPGUI")
application = SapGui.GetScriptingEngine
connection = application.OpenConnection("SAPlogon pad entry",True)
'===Use a series of SendKeys to simulate typing in fields,
'===here I'm doing a Shift-Tab to place the cursor in the client field
'===and place client 015 in it then using the tab I fill the other
'===required field and finish by Enter
ins.Send("+") ins.Send("015") ins.Send("")
ins.Send("username")
ins.Send("") ins.Send("password") ins.Send("")
ins.Send("EN")
ins.Send("")
Hope this helps.
Michel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
First of all thanks for your code... But I'm a newbie with Visual Studio 2005 and it doesn't work: I've created a project ( empty application ) and I've added the SAPGUI Scripting API as a reference ( SAPFEWSELib.dll ).
The method 1 fails in line:
Session = connection.children(0)
Do I need to add any other thing to run this line ?
The method 2 does not recognize the name 'SendKeys'.
Any idea ?
Regards,
Joan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.