This has me stuck. I've tried everything I can and still no joy. Why wont the following work. I'm getting no error messages and the console is writing out the 'Not Found' message so it's doing all the code.

For this example I've stripped the code right down to the most basic. I write text into a column of excel cells with the phrase "FIND ME". I then want to say if the content of the cell (pick one from the populated range of cells) = "FIND ME" then Do stuff. It wont work. I've declared variables etc... here's the relevant code:


VB Code:
  1. moApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)  'Create Excel Object
  2.  
  3.         moApp.Visible = False                                   'Make it invisible
  4.  
  5.         Dim myFileName As String = "D:\My Documents\helpMe2.xls" 'This is the file to open
  6.         Dim oWB As Excel.Workbook = moApp.Workbooks.Open(myFileName)    'Open the workbook
  7.         Dim oSht As Excel.Worksheet = DirectCast(oWB.Sheets("Time"), Excel.Worksheet)  'Open Worksheet Name
  8.  
  9.         Console.WriteLine("Got here")
  10.  
  11.         For i As Integer = 1 To 40
  12.             oSht.Cells(i, 1) = "FIND ME"  'Write Phrase in Cells as a test - it works fine
  13.         Next
  14.  
  15.         If oSht.Cells(10, 1).ToString = "FIND ME" Then  'Example: select a cell from populated range to check
  16.             Console.WriteLine("Found it")
  17.         Else : Console.WriteLine("Didn't Find it")   'This is all I ever get
  18.         End If
  19.  
  20.         oWB.Save()
  21.         oWB.Close(True)
  22.         oSht = Nothing
  23.         oWB = Nothing

I tried assigning the value that was in one of the populated cells to a String variable and then output it:

VB Code:
  1. Dim myValue As String = oSht.Cells(10, 1).ToString   'put value from cell into String
  2.  
  3. oSht.Cells(2, 2) = myValue          'Now output it into different cell to see what it is

All I got was this in the cell: System.__ComObject

What does that mean???

I tried different formats such as these but to no avail:
VB Code:
  1. If oSht.Cells.Item(10, 1).ToString = "FIND ME" Then   'etc
  2.  
  3.  If oSht.Cells(10, 1) Is "FIND ME" Then                      'etc

I'm totally beaten and have gone past the angry stage to just curious as to what the answer is. What have I done wrong? Anyone got the answer please?