Hello,
As I'm new to scripting in SAP (and programming in general) I'm trying to read out an sap grid to excel.
Below is my code which is (partly) working, however it only fills 96 lines in excel.
I tried 'SapGuiGridScrollToRow' to scroll every 90 lines read because I thought it had to do with some 'preloading' of the grid. However this function always gives me an error, so I put it in comments.
Is there a limit on the number of lines that can be read from a grid?
How can I overcome this?
Are there more efficient ways to do this?
Dim xclRow
Dim sapRow
Dim artNr
'Excel
Set xclapp = CreateObject("Excel.Application")
Set xclwbk = xclapp.Workbooks.Add()
' With xclwbk
' .Title = "ArtSer"
' .SaveAs Filename = "artser.xls"
' End With
Set objSheet = xclwbk.Sheets(1)
xclapp.Visible = true
objSheet.cells(1,1) = "Artikelnummer" 'MATNR
objSheet.cells(1,2) = "Serienummer" 'SERNR
xclRow = 2
'session.findbyId(wnd[0]------).Value = objsheet.cells(1,1).value 'for example Never use the Range Object---
'SAP
sapRow = 0
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 = "iq09"
session.findById("wnd[0]").sendVKey 0
'Artikelnummer Fabricom artNr = Inputbox("Geef een artikelnummer:","Artikelnummer") session.findById("wnd[0]/usr/ctxtMATNR-LOW").text = artNr session.findById("wnd[0]/usr/ctxtMATNR-LOW").setFocus 'session.findById("wnd[0]/usr/txtMATNR-LOW").caretPosition = 6 session.findById("wnd[0]").sendVKey 8
Set GRID1 = session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell")
'msgbox(GRID1.rowcount)
for sapRow = 0 to GRID1.rowCount - 1
'session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(sapRow,"MATNR")<>""
objSheet.cells(xclRow,1) = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(sapRow,"MATNR")
objSheet.cells(xclRow,2) = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(sapRow,"SERNR")
'sapRow = sapRow+1
xclRow = xclRow+1
'If sapRow Mod 90 Then
' SapGuiGridScrollToRow "wnd[0]/usr/cntlGRID1/shellcont/shell", sapRow
'End If
next
MsgBox("Done")






