Search code examples
excelsap-guisap-erp

How to run IW29 with a specific variation and layout and copy its outcome to excel?


I'm trying to copy the result I get from running IW29 transaction code with a specific variation and layout to excel. I recorded a script within SAP to run IW29 with the variation and layout I wanted and it goes like below posted code.

What do I need to do in order to copy the information and paste it to a specific Excel file now?

Thanks for your help.

Code:

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "iw29"
session.findById("wnd[0]").sendVKey 0
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").currentCellRow = 1
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/tbar[0]/btn[2]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1,""
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectAll

Solution

  • You could try the following:

    ...
    'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1,""
    'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectAll
    set myGrid = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
    myGrid.selectedRows = "0"
    myGrid.contextMenu
    myGrid.selectContextMenuItem "&XXL"
    session.findById("wnd[1]/usr/cmbG_LISTBOX").setFocus
    session.findById("wnd[1]/usr/cmbG_LISTBOX").key = "08"
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").select
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").setFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    

    And the rest you get from the link: repeating script that goes from SAP to Excel and back again behind the comment: 'Ends Save Portion

    Regards, ScriptMan