【发布时间】:2015-10-14 09:42:53
【问题描述】:
我正在使用 excel VBA 来尝试自动化一些 SAP 数据输入。
我有一个 gridview 控件,我试图在列中查找特定文本,然后双击该单元格以选择它。
我目前正在使用 for 循环来查找行,但得到了一些奇怪的结果。当我单步执行代码时,我可以到达该行但无法选择或双击它。当代码以通常的速度运行时,甚至没有选择行!
有没有更好的方法来解决这个问题?
这是目前为止的代码
Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String)
For i = 0 To grid.RowCount - 1
If grid.GetCellValue(i, columnname) = texttofind Then
grid.DoubleClickCurrentCell
End If
Next i
End Function
我也试过下面的代码:
Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String)
For i = 0 To grid.RowCount - 1
If InStr(1, grid.GetCellValue(i, columnname), texttofind, 1) > 0 Then
If selectedRows = "" Then
selectedRows = CStr(i)
Else
selectedRows = selectedRows + "," + CStr(i)
End If
End If
Next i
grid.selectedRows = selectedRows
End Function
感谢任何帮助!
干杯
【问题讨论】: