Reputation: 1419
I've tried this:
'start Excel app
Dim exApp As Microsoft.Office.Interop.Excel.Application
exApp = CreateObject("Excel.Application")
' load excel document
exApp.Workbooks.Open(fname)
Dim exSheet As Microsoft.Office.Interop.Excel.Worksheet
exSheet = exApp.Workbooks(1).Worksheets(1)
and than, for example accessing "C3" cell:
Dim b As String
b = exSheet.Cells("A3")
or:
b = exSheet.Cells(3,3)
and it throws me an exception. I'm feeling that I'm doing something wrong with the object access, but this method worked in embedded VB, and do not works in .net. Also, tried to google the exception code, with no relevant result.
Upvotes: 0
Views: 26569
Reputation: 33474
I don't think you should write code in VB6 style for vb.net.
Looking at the code example, I think what you need is
b = exSheet.Cells(3,3).Text
or
b = exSheet.Cells(3,3).Value
EDIT: I guess it the reference should be assigned to an instance of range.
So, the code might look like
Range exampleRange = exSheet.Cells(3,3)
b = exampleRange.Text 'OR it can be b = exampleRange.Value
Upvotes: 1