Error importing and exporting excel data to vb.net, "Microsoft.Office.Interop.Excel.Application is not defined"

excel, vb.net, vba

Solution

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).

Problem

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?

Original source