Hello all, I hope this hasn't been answered already. I couldn't find it anyways. All I want to do is to be able to read data from an xlsx file and use it in my VB 2010 application. Ultimately I will be using the excel file to store and load data to be used within my app. At this point I cant seem to even read the file and I am sure I am doing something silly. Here is what I have so far (after adding the two excel references 5.0 and 12):
Dim excelApp As Excel.Application
Dim excelWB As Excel.Workbook
Dim excelWS As Excel.Worksheet
excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelWB = excelApp.Workbooks.Open("C:\Users\Dad\documents\visual studio 2010\Projects\ExcelImport\ExcelImport\Book1.xlsx")
excelWS = excelWB.Worksheets(1)
' this next line is just to test to see if I read the data properly ... and no I didn't
Me.Label1.Text = excelWB.Cells(1, 1).value
it is giving me an error message on my open command. I am not even sure if open is the right method to use. This seems to actually open excel and then the file. What I really want is to just read the file and grab the data. Eventually I would love to be able to write to the file as well but reading it would be great for now.
Thanks in advance.
Dim excelApp As Excel.Application
Dim excelWB As Excel.Workbook
Dim excelWS As Excel.Worksheet
excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelWB = excelApp.Workbooks.Open("C:\Users\Dad\documents\visual studio 2010\Projects\ExcelImport\ExcelImport\Book1.xlsx")
excelWS = excelWB.Worksheets(1)
' this next line is just to test to see if I read the data properly ... and no I didn't
Me.Label1.Text = excelWB.Cells(1, 1).value
it is giving me an error message on my open command. I am not even sure if open is the right method to use. This seems to actually open excel and then the file. What I really want is to just read the file and grab the data. Eventually I would love to be able to write to the file as well but reading it would be great for now.
Thanks in advance.