0

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.

2 Answers 2

2

Try:

b = exSheet.Range("A3").Value.ToString
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this works fine. Do Range method get another parameters, like (x,y) position to iterate through spreadsheet?
Hmm, you can use .Cells, but you would need exSheet.Cells()(3,3).Value2
1

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

1 Comment

Intellisense shows me only ToString, Equals, GetHashCode, GetType and ReferenceEquals. Should I use one of them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.