|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Exception HRESULT: 0x800401A8 in Excel with VB .NetHello
I'm making an application that uses an excel worksheet, My problem appears when I open the worksheet to see the data (then I close it and save the changes) and I try to insert a new row from my application appears the error: System.Runtime.InteropServices.COMException(0x800401A8): Exception HRESULT: 0x800401A8 Thanks for all sgr,
You said your steps are: 1. open workbook 2. read data 3. close workbook 4. save workbook 5. edit workbook My guess is that you are getting that error because the workbook you attempting to change isn't open. Why don't you post some code? That would let us know exactly what you are trying to do. Thanks, Kim Greenlee -- digipede - Many legs make light work. Grid computing for the real world. http://www.digipede.net http://krgreenlee.blogspot.net Thanks Kim,
I opened the taksmanager I saw that the process excel.exe was always running, although I close the application. This is my code: Dim xlsApp As Excel.Application Dim xlsBook As Excel.Workbook Dim xlsSheet As Excel.Worksheet Dim xlsRange As Excel.Range Dim filexls As String = "c:\temp\temp.xls" Private EventDel_BeforeBookClose As Excel.AppEvents_WorkbookBeforeCloseEventHandler Private Sub BeforeBookClose(ByVal Wb As Excel.Workbook, ByRef Cancel As Boolean) closeXls() RemoveHandler xlsApp.WorkbookBeforeClose, EventDel_BeforeBookClose End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'open excel, edit some cells and close it xlsApp = CreateObject("Excel.Application") xlsBook = xlsApp.Workbooks.Add xlsBook = xlsApp.Workbooks.Open(filexls) xlsSheet = xlsBook.Worksheets(1) EventDel_BeforeBookClose = New Excel.AppEvents_WorkbookBeforeCloseEventHandler(AddressOf BeforeBookClose) AddHandler xlsApp.WorkbookBeforeClose, EventDel_BeforeBookClose xlsApp.Visible = True End Sub Public Sub closeXls() xlsBook.Save() xlsRange = Nothing xlsSheet = Nothing xlsBook.Close(False) xlsBook = Nothing xlsApp.Quit() xlsApp = Nothing End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click xlsApp = CreateObject("Excel.Application") xlsBook = xlsApp.Workbooks.Add xlsBook = xlsApp.Workbooks.Open(filexls) xlsSheet = xlsBook.Worksheets(1) xlsSheet.Columns.Clear() EventDel_BeforeBookClose = New Excel.AppEvents_WorkbookBeforeCloseEventHandler(AddressOf BeforeBookClose) AddHandler xlsApp.WorkbookBeforeClose, EventDel_BeforeBookClose xlsSheet.Range("A1:L1").Font.Bold = True xlsSheet.Range("A1:L1").Font.Name = "Verdana" xlsSheet.Range("A1:L1").Borders.Weight = Excel.XlBorderWeight.xlMedium xlsRange = xlsSheet.Range("A1") xlsRange.Value = "Hello" xlsRange = xlsSheet.Range("B1") xlsRange.Value = "5.71" xlsRange = xlsSheet.Range("C1") xlsRange.Value = "9.02" xlsRange = xlsSheet.Range("A3") xlsRange.Value = TextBox1.Text xlsBook.Save() End Sub End Class Show quoteHide quote "Kim Greenlee" wrote: > sgr, > > You said your steps are: > > 1. open workbook > 2. read data > 3. close workbook > 4. save workbook > 5. edit workbook > > My guess is that you are getting that error because the workbook you > attempting to change isn't open. > > Why don't you post some code? That would let us know exactly what you are > trying to do. > > Thanks, > > Kim Greenlee > -- > digipede - Many legs make light work. > Grid computing for the real world. > http://www.digipede.net > http://krgreenlee.blogspot.net >
DataGrid custom class
How to create a local server (i.e., localhost) VB.NET Datagrid Sorting of Numbers For Each Loop in ASP.NET 2.0 VB.NET XML Documentor Configuration File code error difference in Filestream + StreamWriter and just StreamWriter Missing Dll mscoree.dll OFF TOPIC: IL DASM the MSIL disassebler Insufficient key column information for updating or refreshing. |
|||||||||||||||||||||||