SAP & VBA: How to start

Visual Basic for Application can be very helpful when is used for automation in Microsoft Office (especially in Excel). But it is not well known that VBA, together with Excel, can be used in SAP systems (those accessible from SAP Logon, for example SAP ERP, SAP BW).

To start using VBA in SAP, first the SAP Scripting must be enabled. To achieve that:

  1. Open transaction RZ11.
  2. Display parameter sapgui/user_scripting.
  3. Change the value to True.
  4. Reset SAP Logon.

Now, under the Customize Local Layout button the Script Recording and Playback option is enabled.

Script Recording and Playback allow user to record VB scripts in SAP, but the true power of this functionality can be reached when the script is run from Excel.

How to start?

Open the Excel, go to Developer, add new module using menu Insert and inside new module add the following code:

This is just the beginning and the macro doesn’t have any true functionality, but you can run this code and check the result. To do that, first login to any SAP system (you need SAP Easy Access windows), then in Excel run the code – hit F5 in VBA editor.

You should see the message:

But after clicking OK, you will get the message from VBA code:

Instead of message box, you can put a code to be run in SAP. For example, you can open (with VBA) a SE16 transaction and show selection screen for TCURR table. The code to achieve that:

This is just the simple example but it presents how useful can be the VBA in SAP. Another example is described in Simple Excel application with User Form blog post.

3 thoughts on “SAP & VBA: How to start

  • Stéfan

    Dear,
    I’m quite surpised that this code works. “Aplication” takes 2 “P”….
    Further, wich reference do I need to select to make this running?
    Do you have more codes available?
    Thansk for your help.
    Stéfan

    • admin

      Hi Stefan, application in VBA is reserved by the Excel itself, I think that’s why something else must be used (but agree, it’s not really accurate). If you need some more example, please contact me on LinkedIn.

Leave a Reply

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