Record macro in SAP using SAP Script Recording

I’ve already discussed how to Connect to SAP via Excel VBA and 10 code lines you can identify in SAP code. But I haven’t explained how to record a macro in SAP yet. In this article I’m going to explain You step by step how to record a macro in SAP using SAP Script Recording.

Record macro in SAP using SAP Script Recording Morfeus

I am going to show You how to start your first recording, beginning of the new era of your SAP work.

First of all…

You need to open SAP application and log in. After that, having that main SAP window opened, click on the last icon with 2 small wheel gears. From the expanded list please select Script Recording and Playback, like on the image below.

Record macro in SAP using SAP Script Recording options

When You select and click it, the pop up window will appear.

Record macro in SAP using SAP Script Recording record and playback

Please click More button to see more options.

Record macro in SAP using SAP Script Recording record and playback more

In the first place You can see 2 active buttons – Play and Record – and one not active – Stop. You are interested in the Record button. After clicking it every move in SAP will be recorded. When You are finished click Stop button to stop recording.

Here You can also see the directory of your recorded scripts. You can change it if You want to. And You don’t have to bother about the format in the window below the path.

After recording

After You finish your recording go to the place from the directory. There You will see files with the .vbs extension. To see the content of the file just simply right click it, select Open with and choose Notepad.

Record macro in SAP using SAP Script Recording script.vbs

After Notepad loads, the content for logging in will look like this.

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]").resizeWorkingPane 175,37,false
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "user"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "********"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus
session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 10
session.findById("wnd[0]").sendVKey 0

In this case I recorded my attempt to log in to SAP.

Everything after conditionals is your clicks and keyboard types in SAP. You can exchange the first part of your code for the connection code from my Connect to SAP article.

And that’s it!

Now You should know how record macro in SAP using SAP Script Recording. You know where to find it, You know how to use it. It will automate your daily SAP routines and make your daily tasks faster and easier.

Tomasz Płociński

Author: Tomasz Płociński

Excel VBA enthusiast who is also open for other languages. Mainly working in VBA, some SQL, hungry for more.

4 thoughts on “Record macro in SAP using SAP Script Recording”

  1. hi thomasz
    I saw your post about login to sap with macro and it worked fine for me here but, I’m not allowed to record macros with scripting in my work I can just record the login window, after that nothing more appears in the code. seeing your blog I can adapt some code and execute a transaction but I can’t fill the textbox anyway after the transaction is executed. do you have any idea?

    I just added one line after the login code:
    session.findById(“wnd[0]/tbar[0]/okcd”).Text = “iw22”, that’s the transaction after that appears a textbox were I have to added a number..

    I can’t find a way to fill that textbox.

    thanks!!

Leave a Reply

Your email address will not be published. Required fields are marked *