cancel
Showing results for 
Search instead for 
Did you mean: 

Export SAP data to Excel Sheet with VBA

Former Member
0 Kudos

Hello

I'm creating a software base on excel VBA to control some variable cost that are not tracked  on our SAP.

I'm stuck in a problem were I need to import some information for the SAP to the base sheet on excel. I need to creat a VBA code to login my SAP open a transition for exemplo "MB51" add filters and export the result directly to the last empty line on my sheet.

Until now I can login ta SAP run the transition with the filters and show the results, but I can't export the results form SAP to my base sheet, can same one help me me ?


Public Sub SimpleSAPExport()

  

  Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object

  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI

  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected

  Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

     session.findById("wnd[0]").maximize

     session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00007"

     session.findById("wnd[0]/usr/ctxtCHARG-LOW").Text = "4552872B"

     session.findById("wnd[0]/usr/ctxtBWART-LOW").Text = "101"

     session.findById("wnd[0]/usr/txtMJAHR-LOW").Text = "2000"

     session.findById("wnd[0]/usr/txtMJAHR-HIGH").Text = "2015"

     session.findById("wnd[0]/usr/ctxtALV_DEF").Text = "/CPS"

     session.findById("wnd[0]/usr/ctxtALV_DEF").SetFocus

     session.findById("wnd[0]/usr/ctxtALV_DEF").caretPosition = 4

     session.findById("wnd[0]/tbar[1]/btn[8]").press

End Sub

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

Hi Guilherme,

Perhaps you will come through this link to a solution:

Regards,

ScriptMan