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:
- Open transaction RZ11.
- Display parameter sapgui/user_scripting.
- Change the value to True.
- 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.