Error: 0x800A03EC when accessing Excel cells.

M

MadmartiganL

I'm using Windows XP SP2 and MS Office 2007. The following code where I try
to access any cell in any workbook returns "Exception from HRESULT:
0x800A03EC". I'm dead out of ideas and searching the internet wasn't any
help. Hope you guys can help me out here!

Imports Microsoft.Office.Interop

Public Class ExcelLink

Private workbook as Excel.Workbook
Private worksheets() as String
Private app as Excel.Application

Public Sub OpenFile(Byval fileName as String)

app = New Excel.Application
workbook = app.Workbooks.Open(fileName)

End Sub

Public function GetColumns(ByVal sheet As String)

Dim columns() As String
Dim worksheet As New Excel.Worksheet
Dim i As Integer

For i = 1 To workbook.Worksheets.Count()
If workbook.Worksheets.Item(i).Name.Equals(sheet) Then
worksheet = workbook.Worksheets.Item(i)
End If
Next

i = 1

While (worksheet.Cells(1, i).ToString <> "") 'this is where the error is
at, using "A1" etc to select the sell doesn't work either, using Ranges gives
the same problem.

ReDim Preserve columns(i)

columns(i - 1) = worksheet.Cells(1, i)

i = i + 1

End While

End Function
End Class
 
C

Cindy M.

Hi =?Utf-8?B?TWFkbWFydGlnYW5M?=,
Public function GetColumns(ByVal sheet As String)

Dim columns() As String
Dim worksheet As New Excel.Worksheet
Dim i As Integer

For i = 1 To workbook.Worksheets.Count()
If workbook.Worksheets.Item(i).Name.Equals(sheet) Then
worksheet = workbook.Worksheets.Item(i)
End If
Next

i = 1

While (worksheet.Cells(1, i).ToString <> "") 'this is where the error is
at, using "A1" etc to select the sell doesn't work either, using Ranges gives
the same problem.
I have a problem with this code snippet. The Office object models don't support
constructs such as Dim worksheet as New Excel.Worksheet. The objects (with the
exception of the Application) are not classes with exposed constructors. You can
only generate a new worksheet by using the Add method of the Workbook object.

If you're declaring worksheet only to work with it in the for...next loop, take
away the "New".

<<While (worksheet.Cells(1, i).ToString <> "") 'this is where the error is
at, using "A1" etc to select the sell doesn't work either, using Ranges gives
the same problem.>>

You don't show us any code in-context for this, so it's hard to give an opinion,
but... The Excel object model certainly doesn't use ToString and I don't know
what you expect this should give you. If you want to check the *content of the
cell*, then use the Value2 property of the Range object.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top