cancel
Showing results for 
Search instead for 
Did you mean: 

SAP VBScript - ALV Export to Excel & save, close, then return to SAP

Former Member
0 Kudos

I've a question on saving the Excel file after exporting it from a ALV grid.

Say, that I run a report and it is displayed in ALV grid format.

When I record the script, I press the button List > Export > Spreadsheet..., then I press then green tick on "Filter criteria, sorting, totals and subtotals are not taken into account", choose "Table", then "Microsoft Excel". A worksheet appears as "Worksheet in Basis (1)". I then click on "Save As" in Excel, type in a file name, choose a folder to save the file and close the Excel file. It then returns to SAP screen and the dialog box "Save the data in the spreadsheet" disappears.

SAP only records this and did not record anything on saving the worksheet:

session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[1]").select

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

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

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

Do you know any scripts that can help to save the worksheet, close it, and then return to SAP?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Edmund - you cannot save the extraneous commands into the script, i.e. when you move away from SAP to Excel, it stops recording. Instead of calling up excel in-place, save it to an excel file through file export facility within SAP, then manipulate that file in excel vba macros (if you need to perform some manipulation on the data) and switch back to SAP - all within your vbs script. That is how I do it with the data I want to save to Excel from within the vbscript.

cheers

Umur

thomas_brutigam2
Active Participant
0 Kudos

That woul be Possible if you run a second script that takes control of Excel-

So you have to start a script that saves the current opened workbook.

Therefore

type

session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[1]").select

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

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

wscript.Run save_excel.vbs

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

This should start the following script:

Dim xclApp As As Object

Set xclApp = GetObject(, "Excel.Application")

xclapp.ActiveWorkbook.Saveas [here goes your path and filename].xls

xclapp.ActiveWorkbook.close

Set xclapp = Nothing

Probably there are some problems within the code -

i'm writingtwith any connection to sap 

Search the forum for similar posts by the user Scriptman

greetings

Thomas Br