code error, can any one tell me where is the error
hi
pleaze i wrote this code in vb, i want open excel sheet get some data from
at run timel there is an error in line
oBook.OpenLinks("c:/test2.xls",System.Reflection.Missing.Value,System.Reflection.Missing.Value)
the error is "object reference not set to an instance of an object"
then, please look to the line
string1 = oSheet.Range("A1").Value
string2 = oSheet.Range("B1").Value
its true or not
please tell me what can i do? how can i take data from an excel sheet
CODE
'strings to put data from excel sheet
Dim string1 As String
Dim string2 As String
'open workbook in Excel
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
oExcel = New Excel.Application
oExcel.Visible = True
oExcel.UserControl = True
Dim oBooks As Object = oExcel.Workbooks
Dim ci As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
oBooks.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod, Nothing, oBooks, Nothing, ci)
oBook.OpenLinks("c:/test2.xls", System.Reflection.Missing.Value, System.Reflection.Missing.Value)
oBook.Activate()
'Get the first worksheet in the workbook so that you can
'make changes to it
Dim oSheet As Excel.Worksheet
oSheet = oBook.Worksheets(1)
string1 = oSheet.Range("A1").Value
string2 = oSheet.Range("B1").Value
oBook.Save()
oBook.Close()
oExcel.Quit()