Excel macros for SAP GUI – the secret method?

Macros Excel SAP GUI

Make your work easier with Excel macros for SAP GUI.

In this article, we are going to learn how to link an Excel sheet to SAP GUI.

If you are just starting with SAP GUI macros, I recommend checking out my first article which introduces SAP macros.

If you prefer the video version, here it is:

Allow macros in Excel

  1. Create a new Excel workbook
  2. Go to “File” then “Options”
  3. Then go to “Customize Ribbon”
  4. Tick the “Developer” checkbox in the right section
  5. Click “OK”

Allow access to SAP GUI in Excel

  1. Go to the “Developer” tab that has just been enabled, then click “Visual Basic” on the far left

  1. Go to the “Tools” menu, then click “References”

  1. Click “Browse” and type the following path in the search bar:

C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewse.ocx

  1. Click “Open”
  2. Check that “SAP GUI Scripting API” is ticked, then click OK

Analysis of the Excel macro that allows you to connect to SAP GUI

To get the code that will let you create your macros, go to this page where you can download the file

You will find all the explanations of the code in the file. Everything is explained in detail.

Testing the Excel macro connected to SAP GUI

  1. Create a button in your Excel sheet. To do this:
    • Go to Insert -> Illustrations -> Shapes and choose the shape you want
  2. Then assign your macro to the button:
    • Right click the button, choose “Assign Macro”, select “Macro SAP” in the menu, then click “OK”
  3. Click the button and the macro starts running. Make sure you are connected to SAP beforehand.

Warning: Do not forget to save your Excel file as .xlsm (the extension that allows macros in an Excel file). If you save it as a standard .xlsx, your macro will be deleted! (All that work for nothing, that would be a shame..)


You now know how to run an SAP macro directly from Excel.

I invite you to check out the third and final part of this trilogy. There, we cover how to:

  • Insert a file exported from SAP directly into the Excel file
  • Include editable parameters in the sheet so you can change them very quickly without going into the code
  • Other tips that will be very useful to you


To go much further with Excel SAP GUI macros

If you want to be able to exploit the full potential of Excel SAP GUI macros, I invite you to check out my training, which is much more comprehensive. In particular, we cover how to:

  • Retrieve information from an SAP transaction and import it into an Excel file
  • Enter information into an SAP transaction from data stored in an Excel file
  • Chain several SAP GUI macros one after another
  • Send an automatic email report containing data from several SAP GUI transactions
  • Plenty of tips and advice

You will become a true hero of SAP GUI macros.

Related articles