My coding sucks, I very new to .Net programing. So I'll try to explain this mess and post some of my code if necessary. On my main form I open a filediaglog and open a xls, create my class object that handles opening and returning the spreadsheet to the main form, the main form the works with data in it basically reads it line by line and inputs data back in. That all works dandy. When I call the close sub I wrote in the class that does the opening of the xls. It's like it sets all my Workbook/Worksheet/App values to nothing. So there for I understand the workbook object can't call the save method when it does have anything to save. Here is my class code:
Code:Imports Microsoft.Office.Interop Public Class ClientValidation Public StrFile As String Public ExWb As Excel.Workbook Public ExSheet As Excel.Worksheet Public ExRange as Excel.Range Public ExApp As Excel.Application Public Function OpenExcel() As Excel.Worksheet ' Create new Application. Dim exApp = New Excel.Application Dim exWb as Excel.Workbook Dim exSheet as Excel.Worksheet 'Dim exRange as Excel.Range exwb = exApp.Workbooks.Open(StrFile) exSheet = DirectCast(exWb.Worksheets(1),Excel.Worksheet) Return ExSheet End Function Public Sub Save() ExWb.Save() 'exWb. End Sub Public Sub Close() ExWb.Save() 'exRange = Nothing exSheet = Nothing exWb = Nothing ExApp.Quit() exApp = Nothing End Sub Public Function RecordCount() As Integer ExRange = ExSheet.UsedRange RecordCount = ExRange.Rows.Count()-1 End Function End Class


LinkBack URL
About LinkBacks




Reply With Quote


Bookmarks