I'm working on a function that reads an excel spreadsheet into a multidimensional array, but when I go to debug the program in VS2005 it runs fine, but when I was trying to debug some other stuff and stepping through the program, the function doesn't work. When the program gets to Dim RouteArray As Object(,) = excelSheet.UsedRange.Value, it errors out with HRESULT: 0x800401A8. Doesn't look like it matters what is in the worksheet either...i created a new worksheet with just a few numbers and still get the same error. I haven't programmed since college, so any help is appreciated.
Code:
Public Function getWriteSchedule(ByVal sheet As String) As Object
Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
Dim excel = New Microsoft.Office.Interop.Excel.Application()
excel = CreateObject("Excel.Application")
excel.Workbooks.Open(SchedulePathTextBox.Text)
Dim excelSheet As Microsoft.Office.Interop.Excel.Worksheet
excelSheet = excel.Workbooks(1).Worksheets(sheet) '
Dim RouteArray As Object(,) = excelSheet.UsedRange.Value
excel.Workbooks.Close()
excel.quit()
excel = Nothing
excelSheet = Nothing
Return RouteArray
End Function
Last edited: