473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Exception HRESULT: 0x800401A8 in Excel with VB .Net

sgr
Hello
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(0x8004 01A8): Exception
HRESULT: 0x800401A8

Thanks for all
Aug 2 '06 #1
2 17279
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

Aug 2 '06 #2
sgr
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(Ad dressOf 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(Ad dressOf 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
"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
Aug 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven | last post by:
Hi there, I am trying to export a chart using the Excel11 object from C#. I can properly open workbooks and read cells, but calling Export() on the Chart object throws a COMException ...
4
by: Mark | last post by:
I have a COM object that calls into a C# Forms library. The library can throw exceptions and I want to handle the exceptions in COM. Adam Nathan wrote a Microsoft sponsored book titled .Net and Com...
8
by: scorpion53061 | last post by:
Additional information: Exception from HRESULT: 0x800A03EC. This code produced this error. I am pretty sure I got this to run a while back and I was wondering if you all see anything I am doing...
2
by: Sai | last post by:
Hi, I have written a small tool for our internal purpose in VB.net. This tool reads data from logs and saves it in an excel file. This tool is working fine with MS Office 2000 but raising the...
4
by: Shimon Sim | last post by:
I just switch my asp application to .net 2 and got this error. Any reasons why? Thank you. Server Error in '/RAFEmployee' Application....
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
0
by: rGh | last post by:
Hello, I am trying to create an Excel chart from C#. I am not a very experieced programmer, so my mistake could be very trivial. The code included is a very simple example. I just wanted to...
0
by: hne | last post by:
Hi friends, I have an application, written in C#, in which I am updating an Excel spreadsheet with data I pull from a sql database. When I try to select a cell in where I want to begin inserting my...
4
by: yogarajan | last post by:
The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.