Excel from vb and an hresult exception

wildfire1982

Well-known member
Joined
Oct 23, 2003
Messages
50
Location
Southampton
Hello folks,

I have used excel from vb.net loads of times and normally manage it with no problems. This time, I have one event opening the spreadsheet and associating it with an object, and then another event which writes to the spreadsheet. Everything seems fine apart from when it is run and the line which the error occurs in should simply write to a cell. I get the message HRESULT: 0x800A03EC. The objects are defined in the main body of the code as public and each of the events metioned earlier refer to these. Anyone had this problem before? Im sure its probably just me being stupid as usual but I cant see where im going wrong.

Cheers for any ideas.

Chris
 
I have had the same error, and searched for it for about an hour, eventually I found the solution.
I had written a loop to write different values into different cells. It went something like this:

for i = 0 to 10
sheet.cells("A" & i) = "test"
next

Actually its quite obvious, but there is no cell "A0" :-)
You should start counting from one...
 
I got the following error :
Exception from HRESULT: 0x800A03EC.

Which is the same.

Im doing it on ASP.NET with C#. I want the server-side to interpret Data from a excel file.

Here is my code :

C#:
[size=2][color=#0000ff]private[/color][/size][size=2][color=#0000ff]void[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.EventArgs e)[/size]
[size=2]{[/size]
[size=2]     Workbooks oWbs = [/size][size=2][color=#0000ff]null[/color][/size][size=2];[/size]
[size=2]     Workbook oWb = [/size][size=2][color=#0000ff]null[/color][/size][size=2];[/size]
[size=2][color=#0000ff]     try[/color][/size]
[size=2]     { [/size]
[size=2]          oWbs = oExcel.Workbooks;[/size]
[size=2]          oWb = oWbs._Open(@"C:\Inetpub\wwwroot\Location\tests.xls",[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2],[/size][size=2][color=#0000ff]null[/color][/size][size=2], [/size][size=2][color=#0000ff]null[/color][/size][size=2]);[/size]
[size=2]          Response.Write("It works");[/size]
[size=2]          Response.Write("<br>");[/size]
[size=2]     }[/size]
[size=2][color=#0000ff]     catch[/color][/size][size=2](Exception ex)[/size]
[size=2]     {[/size]
[size=2]          NAR( oWbs );[/size]
[size=2]          NAR( oWb );[/size]
[size=2]          oExcel.Quit();[/size]
[size=2]          NAR(oExcel);[/size]
[size=2]          Response.Write( ex.Message );[/size]
[size=2]     }[/size]
[size=2]}[/size]

Thanks
 
Thats it. I solved the problem... I think :D

I changed Open(filename) by Add(filename) and it work. At least it return a value.

Oh... yes I set the right permission to ASPNET account (fullcontrol). I think its maybe an old command for older Excel or something or I dunno.

I have another problem with getting the right range.
I want to have all columns header (A1:A??).
But it said invalid type :

Code:
Range rng = ws.Columns.get_range( ws.Columns.Cells["A", "1"], ws.Columns.Cells["A", ws.Columns.Count.ToString()];
 
However ... here is my exact code :
Code:
[size=2][color=#0000ff]public[/color][/size][size=2][color=#0000ff]string[/color][/size][size=2] [] GetColumnsHeaders()
 
{
 
Range rng = [/size][size=2][color=#0000ff]null[/color][/size][size=2];
 
[/size][size=2][color=#0000ff]try
 
[/color][/size][size=2]{
 
rng = m_ws.Columns.get_Range( m_ws.Columns.Cells["A",1], m_ws.Columns.Cells["A", m_ws.Columns.Count]);
 
[/size][size=2][color=#0000ff]string[/color][/size][size=2] [] test = [/size][size=2][color=#0000ff]new[/color][/size][size=2][color=#0000ff]string[/color][/size][size=2][rng.Count];
 
NAR( rng);
 
[/size][size=2][color=#0000ff]return[/color][/size][size=2] test;
 
}
 
[/size][size=2][color=#0000ff]catch
 
[/color][/size][size=2]{
 
NAR( rng );
 
Dispose();
 
[/size][size=2][color=#0000ff]return[/color][/size][size=2][color=#0000ff]null[/color][/size][size=2];
 
}
 
}
 
[/size]

[edit2]The NAR function is the one that were so much talked about but translated to C#.[/edit2]
 
Stop everything there.
Im stupid and I admit it.

m_ws.Cells[1,1] work better than m_ws.Cells["A", 1].

You can throw me rocks if you want.
It seems to calm stupidy in my damn head also.

Thanks anyway dude !
 
Back
Top