prob with "Object reference not set to an instance of an object" error
Hi all,
I have a vb.net program that sets up an excel sheet, and enters data from textboxes on a form into the first row of the excel sheet, which then can be exited disposing of resources. What i now need is to re-open the same excel sheet with the saved line of data, and enter new data into the next available free row of the excel sheet. I can open the sheet, but when I try to enter the data i get the "Object reference not set to an instance of an object" error. I have got very confused about why this is happening, and am hoping someone can tell me what changes i need to make to get this to work. I guess I need to refer to the object which is called using getobject, but I am not sure how.
Code:
checks for the excel file, uses getobject if the file exists
Sub OpenXLWorkBook(ByVal unidimensional_data)
Dim xlApp As Excel.Workbook
Dim xlWindow As Excel.Window
'Check to see if the file name passed in to
'the procedure is valid
If Dir("c:\unidimensional_data\data.xls") = "" Then
'MsgBox("'" & "c:\unidimensional_data\data.xls" & "' isn't a valid path!")
Call xlsetup()
'Exit Sub
Else
xlApp = GetObject("c:\unidimensional_data\data.xls")
'Show the Excel Application Window
xlApp.Parent.Visible = True
xlApp.Windows(1).Visible = True
'Unhide each window in the WorkBook
'For Each xlWindow In xlApp.Windows
' xlWindow.Visible = True
' Next
'Prevent Excel from prompting to save changes
'to the workbook when the user exits
xlApp.Saved = True
End If
define the row and column of sheeet
Public row As Integer
Public column As Integer
look for a blank cell, add one to the row number until found then write value of text box to the cell
Private Sub tbox_subnum_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_subnum.TextChanged
row = 1
column = 1
Do Until (xlsheet.Cells(row + 1, column).value = "")
error appears to be on the 'value' in the line of code below
xlsheet.Cells(row, column).value = tbox_subnum.Text
Loop
'Call change(2, 1)
End Sub
Cheers in hope
Stu