my starting problem was to select a number of rows out of a existing selection of rows in a SAP GUI GridView (e.g. the first 5 lines out of 1,2,4-8,10). I've planned to check each row if it's selected and count the selcted rows until the number of rows is reached. After that I planned to deselect the following rows.
Finally I solved the problem with the following code:
Set objGRID1 = SAPSession.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
If objGRID1.RowCount = 0 Then
MsgBox "Keine Daten vorhanden!!" & Chr(10) & "Makro wird beendet!", vbCritical
End
End If
strStartRows = objGRID1.selectedRows
strStartRows = strStartRows & ",,"
strBins = ""
intCounter = 0
Do
strCheck = Left(strStartRows, InStr(1, strStartRows, ",", 1) - 1)
If InStr(1, strCheck, "-", 1) > 0 Then
For intDurchlauf = CInt(Left(strCheck, InStr(1, strCheck, "-", 1) - 1)) To CInt(Right(strCheck, Len(strCheck) - InStr(1, strCheck, "-", 1)))
strBins = strBins & intDurchlauf & ","
intCounter = intCounter + 1
If intCounter >= intMaxBins Then
Exit Do
End If
Next intDurchlauf
Else
strBins = strBins & strCheck & ","
intCounter = intCounter + 1
If intCounter >= intMaxBins Then
Exit Do
End If
End If
strStartRows = Right(strStartRows, Len(strStartRows) - InStr(1, strStartRows, ",", 1))
Loop Until strStartRows = ","
objGRID1.selectedRows = Left(strBins, Len(strBins) - 1)
It works fine, but probably it's not the best code for this. Please feel free to correct, if there's something to do better.
Thanks for your help,
Lutz