Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Jan 12, 2015 at 10:42 PM


    Add comment
    10|10000 characters needed characters exceeded