Hello guys,
I have a question here. When I run my code the Excpetion form HRESULT:
0x800A03EC is thrown out. I have two forms in this program, and both of them
are trying to open the same Excel file. Public Class Form2 is putting data
into Excel, and Public Class ButtonArray is trying to open the Excel file
and read the data. Following is my part of my code related to this problem.
The sub procedure in Form2 class:
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.
EventArgs) _
Handles Me.Load
' Bind the DataGridView to the BindingSource
' and load the data from the database.
Me.dataGridView1.DataSource = Me.bindingSource1
GetData("select e.eqpid, e.status,e.changedt, c.seqnum as
comment_cnt, c.eqpscomment" + _
" from eqps e, eqps_comments c" + _
" where c.rectype='C' and e.rectype='C'" + _
" and e.eqpid = c.eqpid order by e.eqpid,c.seqnum")
Dim oXLApp As Excel.Application
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
' Dim oRng As Excel.Range
' Start Excel and get Application object.
oXLApp = New Excel.Application
oXLBook = oXLApp.Workbooks.Open("C:\Documents and Settings\intern\My
Documents\gogogo.xls")
'Open an existing workbook
oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet
Dim r As Integer
Dim c As Integer
For r = 0 To Me.dataGridView1.Rows.Count - 1
For c = 0 To Me.dataGridView1.Rows(r).Cells.Count - 1
Dim s As String = Me.dataGridView1.Rows(r).Cells(c).Value
oXLSheet.Cells.Item(r + 1, c + 1).Value = s
Next
Next
oXLApp.Visible = False
oXLBook.Save()
' Ensure that the save command is fully completed
Do While Not oXLBook.Saved
Application.DoEvents()
Loop
' Then close the Workbook
oXLBook.Close()
End Sub
The Sub procedure in ButtonShow Class:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles Button1.Click
Dim oXLApp As Excel.Application 'Declare the object
variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
' Start Excel and get Application object.
oXLApp = New Excel.Application
oXLBook = oXLApp.Workbooks.Open("C:\Documents and Settings\intern\My
Documents\gogogo.xls")
'Open an existing workbook
oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet
oXLApp.Visible = True
Dim aButton As New System.Windows.Forms.Button()
For i = 1 To 1000
If CType(oXLSheet.Cells.Item(1, i).Value, String) = aButton.Name
Then
b = oXLSheet.Cells.Item(2, i).Value
Select Case b
Case b = "AVAIL"
aButton.BackColor = Color.Green
Case b = "OFFLINE"
aButton.BackColor = Color.Aqua
Case b = "IDLE"
aButton.BackColor = Color.Blue
Case b = "UMAINT"
aButton.BackColor = Color.Brown
Case b = "SETUP"
aButton.BackColor = Color.Coral
End Select
End If
Next
oXLSheet = Nothing
oXLBook = Nothing
oXLApp = Nothing
End Sub
When the program goes to "If CType(oXLSheet.Cells.Item(1, i).Value, String)
= aButton.Name" in ButtonShow Class The exception I mentioned above is
thrown out.
Could anybody help me out? Thanks a lot in advance.
Harry Miller [MSFT] - 07 Mar 2007 19:16 GMT
Excel throws that exception when the solution running in an environment with
a language other than English. Have a look at this article and see if it
helps:
Creating Excel Solutions for Use in Multiple Countries/Regions Using Visual
Studio Tools for Office
http://msdn2.microsoft.com/en-us/library/aa537159(office.11).aspx

Signature
Harry Miller
This posting is provided "AS IS" with no warranties, and confers no rights.
> Hello guys,
> I have a question here. When I run my code the Excpetion form HRESULT:
[quoted text clipped - 109 lines]
>
> Could anybody help me out? Thanks a lot in advance.