on 03-06-2013 11:36 AM
Hello, I am lookin for help.
I have a script which goes to SU01 and select the filed CLASS in user master record. I would like to export the field value of field CLASS into my VBA where I start the SAP scripting. Enclosed my code which does not work.. Thanks for help. Nguyen
Sub test()
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("xxx", True)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "xxx"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "xxx"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "xxx"
session.findById("wnd[0]").resizeWorkingPane 120, 37, False
session.findById("wnd[0]/tbar[0]/okcd").Text = "SU01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").Text = "xxx"
session.findById("wnd[0]/tbar[1]/btn[7]").press
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").Select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/ctxtSUID_ST_NODE_LOGONDATA-CLASS").SetFocus
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/ctxtSUID_ST_NODE_LOGONDATA-CLASS").caretPosition = 5
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/ctxtSUID_ST_NODE_LOGONDATA-CLASS").Text = n '--------->error, does not work, what is the correct code?
session.findById("wnd[0]/tbar[0]/btn[15]").press
session.findById("wnd[0]/tbar[0]/btn[15]").press
MsgBox n
session.findById("wnd[0]").sendVKey 0
End Sub
Hi Nguyen Huynh,
I would try this:
. . .
n = session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/ctxtSUID_ST_NODE_LOGONDATA-CLASS").Text
. . .
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Script man,
I hope you're fine and Thanks for your last clarification for my quest.
Now I need a help from you. I don't know how to open a new post and also i tried to send a direct message to you. But I couldn't. Thats why I place this query here. Please help.
I 'm using the follwing (your) code to connect Excel & SAP and have created many automations. All of them are working very fine except one.
The SAP window closes after macro run is completed.
Could you please provide me a code which will not close SAP window after macro run is finished.
And also please provide me a code to transfer data from Excel to a opened (manually) SAP window.
Your timely reply will help me more to work out.
Thanks ScriptMan.
Code:
Set SAP = CreateObject("SAP.Functions")
Set conn = SAP.connection
If Not IsObject(SapGuiApp) Then
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(connection) Then
Set connection = SapGuiApp.OpenConnection("051 - PRD - EP1", True)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
UserName = InputBox("Please Enter Your User Name")
Password = InputBox("Please Enter password")
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = UserName
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = Password
session.findById("wnd[0]").sendVKey 0
Hi Mohanram,
Try declaring the SAPGuiApp as a Public variables (on top of the VBA module) instead of a Private variable within that sub procedure. This way, the SAPGuiApp object will not be reset to 'Nothing' when the procedure ended, hence, not ending the SAP session.
Another way, I prefer using the set SAPauto = getObject("sapgui") and set SAPGuiApp = SAPAuto.GetScriptingEngine method. This way, the script will bind to a running sapgui application instead of running as an object within the script (using the CreateObject("SAP.Function") method.
Thanks,
MSA
Thank you very much Azmi !!!!
I tried the second one and its working !! Script is not closing the SAP session after macro run.
Is it possible for a script to read and enter into a "logged in" SAP session ?
As of now the script is opening a new session and asks for username, password and then enter into that.
Please advise as this will be more helpful for me.
Thanks
Ram
Hi Ram.
Yes you can. You may want to refer to another discussion between myself and Stefan here: http://scn.sap.com/message/13966664#13966664
Thanks,
MSA
Very thanks Azmi. I took code from the above conversation and modified it according to the environment which i have here. Its working very fine. We're able to save plenty of time due to the automation that i'm doing. All the credits to you only Azmi !!!! Thanks again for your great help on this !!!!!!
User | Count |
---|---|
96 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.