cancel
Showing results for 
Search instead for 
Did you mean: 

how to get data from SAP into the excel

Former Member
0 Kudos

Hi all,


I need data from SAP to excel using VBA. till now I was able to log into SAP and run the desired transaction I need using excel and VBA now my second biggest Challenge is to export the data I see in SAP into the excel sheet. there are options in SAP to export the data but I need to do it using the VBA. Kindly help me


Please see below the VB code I have written so far, but its just takes me to the data I need but now as I said my second biggest chalange is to get that data from SAP back to Excel.



Sub TEST()

'setting the connection with sap:

Dim App, Connection, session As Object

Set SapGuiAuto = GetObject("SAPGUI")

Set App = SapGuiAuto.GetScriptingEngine

Set Connection = App.Children(0)

Set session = Connection.Children(0)

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

session.findById("wnd[0]/tbar[0]/okcd").Text = "iw29"

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

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

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

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellColumn = "TEXT"

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

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

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1, ""

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").SelectAll

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&XXL"

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

End Sub




Regards,

Imran

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

I had a similar issue some time ago, I just updated the post with the working script:

http://scn.sap.com/message/14864385

This script will start IQ09, ask for a material number, look up all serialnumbers and copy 2 columns to excel (only works when multiple serialnumbers are available).

Tim

holger_khn
Contributor
0 Kudos

Hello Imran,

you should review this document posted by Stefan:


http://scn.sap.com/docs/DOC-26251

There it is explained how to catch ALVGrid into CSV-file. Same functionality can be used to fill Excel fields.

Cheers,

Holger