5
votes

I am trying to run a file I downloaded to import and export data from excel. I downloaded from from the following site:

http://www.sattsoft.com/sourcecodes/details/1/9/import-export-data-to-excel-using-vb-net.html

When I run the file the error comes on the following lines

    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet

These are the errors that come on those respective lines

Type "Microsoft.Office.Interop.Excel.Application is not defined"

Type "Microsoft.Office.Interop.Excel.Workbook is not defined"

Type "Microsoft.Office.Interop.Excel.Worksheet is not defined"

What I want to do is to run the file without the errors so that I can import and export data from excel to vb.net datagridview. I am using Excel 2010 and visual studio 2010

How do I get around this error so I can run the file?

2
Did you download the example source code? Presumably that compiles without error?Matt Wilko
See the first link HERESiddharth Rout
Yes I am running that. I think the file will be fine as CodeProject.com recommended it.Ahmed Faizan
@ Siddharth Thanks that is a great linkAhmed Faizan
Glad to be of help :)Siddharth Rout

2 Answers

8
votes

Add COM reference Microsoft.Office.Interop.Excel to your project, it's called Microsoft Excel XX.Y Object Library (XX.Y is version number depending of installed Excel).

0
votes

I had to use this library in references from the "Extensions" section (not not under COM); had to select Microsoft.Office.Interop.Excel, version 15.0.0.0. That fixed the error. Selecting the COM reference did not resolve this message.