on 01-26-2012 5:08 AM
Hi,
Just a question, if I wanted to record a SAP Script VB, without having to go into SAP and click on Alt+12 -> Script Recording and playback -> Record button, is it possible to do this via Excel VBA only?
For example, I have my SAP window open, but I switch to excel, click on the excel macro for the VB script, it then switches to SAP and begins recording. The resulting code is then pasted or written onto the excel sheet. Is this possible?
Julius
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scriptman,
Thanks for your answer. I checked out the link you gave and it points to a seperate application provided by SAP in the marketplace.
However, I was looking for something more like this:
http://www.youtube.com/watch?v=I3i9TLhRXFc
As you can see, using only excel, the person records the macro and stores it somewhere, is able to isolate manual text inputs by the user, and then allows the user to input his or her own values (probably for loops as well), all done through excel, with the SAP window just open in the background.
The excel file showed in the video is actually exactly what I'm trying to build!
Hi,
Please use the code on scn.sap.com/docs/DOC-57020 to edit your original recorded/programmed script by adding the top and bottom parts in the script and ensuring the quantity of columns are corresponding to your input parameters.
Then add the following as a module in your excel sheet
Sub RFX()
fil = "wscript " & Chr(34) & Environ("AppData") & "\SAP\SAP GUI\script.vbs" & Chr(34)
Shell fil, vbNormaFocus
End Sub
Replace "\SAP\SAP GUI\Script.vbs"with your scripts corresponding path. For many this will be \SAP\SAP GUI\Scripts\Script.vbs. In your excel sheet put a button and attach this macro to it assuming you have a Macro enabled sheet *.xlsm? . Then execute . I Suggest you also set screenupdating to false .
The Environ("AppData") is used to allow the sheet to be re-used by different users on Windows installations.
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/lbl[20,8]").setFocus
session.findById("wnd[0]/usr/lbl[20,8]").caretPosition = 5
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]").sendVKey 71
session.findById("wnd[1]/usr/txtRSYSF-STRING").text = "116011313"
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[2]/usr/lbl[20,2]").setFocus
session.findById("wnd[2]/usr/lbl[20,2]").caretPosition = 5
session.findById("wnd[2]").sendVKey 2
session.findById("wnd[0]/usr/lbl[20,23]").caretPosition = 2
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/tbar[1]/btn[13]").press
session.findById("wnd[0]/tbar[1]/btn[5]").press
session.findById("wnd[1]/usr/txtBKPF-BKTXT").text = "NSPA_1000013021"
session.findById("wnd[1]/usr/txtBKPF-XBLNR").text = "V116011313"
session.findById("wnd[1]/usr/txtBKPF-XBLNR").setFocus
session.findById("wnd[1]/usr/txtBKPF-XBLNR").caretPosition = 1
.Please help me how write this code in excel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.