0

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
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

0

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

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
  • Hi ScriptMan. Thanks for the answer. I'm sorry, but I'm not an IT guy. Should I insert this piece of code in the end of my SAP script? – Rafael Venturini Dec 12 '18 at 14:44
  • Yes, you can it try. ;-) – ScriptMan Dec 12 '18 at 17:33
  • I would only like to add that during the process of developing the code (with your help and other forums) I found out that I could integrate this piece of code into my VBA code. The only thing I had to do in order to make it work in Excel was replacing the word "application" by "guiapplication". Now everything's running from excel. – Rafael Venturini Dec 14 '18 at 11:16