Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Save SAP file as spreadsheet to desktop using VBA

Hello all,

I've scoured the internet and hit a wall.  Below is as far as I've gotten with a macro I'm attempting.  I need to enter a SAP transaction, enter a part number and serial number, and save the resulting information as a spreadsheet to my desktop.  From there my JAVA code will take that spreadsheet and work it's magic.

I'm having a hard time discovering how to code the saving of the file (can't record that part).

How do I control both the file format and the file path?

Thank you in advance.

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

    'Start the transaction to view a table
    session.StartTransaction "YQMCONFIGRPT"
 
    'enter part specific information
    session.findById("wnd[0]/usr/ctxtW_MATERIAL").Text = "3842151-3"
    session.findById("wnd[0]/usr/txtW_SERNR").Text = "14-168522-05838"
    session.findById("wnd[0]").sendVKey 0

   
    session.findById("wnd[0]/usr/btnDOWNLOAD").press 'starts the download
   
    'lost here, how do I controll the file format and save location
   
    session.findById("wnd[0]/tbar[0]/btn[15]").press 'exit transaction
End Sub

Former Member
Not what you were looking for? View more on this topic or Ask a question