cancel
Showing results for 
Search instead for 
Did you mean: 

VBA won't read all the data on a grid

0 Kudos
1,072

Hello,

I have written a code in order to get data from 2 columns on an MM60 grid, so I put the data in a dictionary and then manipulate them as I want. My problem is that the dictionary fills OK up to a certain point and then suddenly no more data are passed on, despite the fact that loop continuous for the full amount of lines on the grid. I wonder if anyone has any explanation for this.

The code is below and I have used a class module to accommodate the dictionary. Any help would be greatly appreciated:


Dim blow As Object

Dim oMaterial As Material_Class
Dim finalrow As Long
Dim TableAddressMM60 As Object
Dim i, j As Long
Dim ThisSKU As String
Dim ThisMAterial As String

On Error Resume Next
Dim SapGuiAuto As Object
Dim LRW As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim Session As SAPFEWSELib.GuiSession

Set blow=createobject("scripting.dictionary")

Set SapGuiAuto = GetObject("SAPGUI")
If SapGuiAuto Is Nothing Then
Exit Sub
End If

Set LRW = SapGuiAuto.GetScriptingEngine
If LRW Is Nothing Then
Exit Sub
End If

Set Connection = LRW.Children(0)
If Connection Is Nothing Then
Exit Sub
End If

Set Session = Connection.Children(0)
If Session Is Nothing Then
Exit Sub
End If
On Error GoTo 0

Session.findById("wnd[0]").maximize
Session.StartTransaction ("MM60")
Session.findById("wnd[0]/usr/btn%_MS_MATNR_%_APP_%-VALU_PUSH").press
Session.findById("wnd[1]/tbar[0]/btn[24]").press
Session.findById("wnd[1]/tbar[0]/btn[8]").press
Session.findById("wnd[0]/tbar[1]/btn[8]").press

Set TableAddressMM60 = Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
finalrow = Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").RowCount - 1

For i = 0 To finalrow

ThisSKU = Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(i, "MATNR")
ThisMAterial = Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(i, "KTEXT")

Set oMaterial = New Material_Class

oMaterial.SKU60 = ThisSKU
oMaterial.Material60 = ThisMAterial

If (Not blow.Exists(oMaterial)) Then blow.Add oMaterial, oMaterial
'If ThisSKU = "" Then Stop
'End If


Next i

Accepted Solutions (0)

Answers (1)

Answers (1)

vincentkuo
Explorer
0 Kudos

You need to move the current cell of SAP Grid table in the loop as below

if i Mod 10 = 0 Then

Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").SetCurrentCell i, "MATNR"

DoEvents

End If