1

I am trying to write some code to extract data from sap, and then put it into an Excel table. Right now, I have the GUI getting into the right itemnumber. Here, I have been trying to get some useful code, using the GUI recorder. I have tried to select the data, and open details and selected data here. The trouble I am having is that the code generated by GUI does not give me .value or .setfocus or something like this. So I do not know how to approach this. The code from GUI can be seen below:

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nymm_pricelist"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtS_MATNR-LOW").Text = Cells(currentline, 1).Value
session.findById("wnd[0]/usr/ctxtS_VKORG-LOW").Text = Cells(currentline, 2).Value
session.findById("wnd[0]/usr/ctxtS_VKORG-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtS_VKORG-LOW").caretPosition = 4
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").CurrentCellColumn = "LOCALSALES_KBETR"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows = "0"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").ContextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").SelectContextMenuItem "&DETAIL"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").setCurrentCell 4, "VALUE"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "4"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").ContextMenu
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").CurrentCellRow = 8
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "8"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").ContextMenu
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").CurrentCellRow = 10
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "10"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").ContextMenu
session.findById("wnd[1]/tbar[0]/btn[0]").press

Any ideas of how to do this?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Sidvi
  • 101
  • 1
  • 2
  • 8

1 Answers1

1

You could try the following:

. . .
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").ContextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").SelectContextMenuItem "&DETAIL"
set myGrid = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell")
myText_4 = myGrid.getcellvalue (4,"VALUE")
myText_8 = myGrid.getcellvalue (8,"VALUE")
myText_10 = myGrid.getcellvalue (10,"VALUE")
session.findById("wnd[1]/tbar[0]/btn[0]").press

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9
  • Thank you, i will try it out when i solve a new issue i have with excel not connecting to sap right... – Sidvi Nov 08 '17 at 10:36
  • Sorry, just accidentally deleted the wrong question. But thank you, your suggestion worked. I ran it on some part numbers and got some info, only then i could see that the sap context detail was not setup the same way for all part no's so i was not getting the information i needed for all numbers. – Sidvi Nov 08 '17 at 11:35
  • Maybe you can help me with this instead then? https://stackoverflow.com/questions/47177189/getting-specific-cell-data-from-sap-to-excel – Sidvi Nov 08 '17 at 11:41