Hello,
I have an application that refers to an existing excel workbook and I am trying to retreive values from group of cells in a worksheet using a loop.
There doesn't seem to be a problem if I use excelSheet.Range("C6").val
ue.tostrin
g, but if I try to use excelSheet.Cells(6,y).toSt
ring it only returns "System.__ComObject" instead of the cell value. I can't seem to figure out why.
Here is my code (I "defactored" it for readability):
Public excelApp As Excel.Application
Public excelWb As Excel.Workbook
Public excelSheet As Excel.Worksheet
Public excelSheet As Excel.Worksheet
Public testSettings As Excel.Worksheet
excelApp = New Excel.Application
excelWb = CType(GetObject(excelPath(
)), Excel.Workbook
testSettings = CType(excelWb.Sheets("test
Settings")
, Excel.Worksheet)
excelSheet = CType(excelWb.Sheets(testS
ettings.Ra
nge("B5").
Value), Excel.Worksheet)
Public Sub loadFieldValues(ByVal testName As String)
Dim x As Integer ' rows
Dim y As Integer ' columns
For y = 3 To 25
If excelSheet.Cells(6, y).ToString = testName Then 'here is the problem (.Range works but I can't loop with it)
Exit For
End If
Next
End Sub
Start Free Trial