ComException error filling excel range with values

F

Franck

Hi,
I'm just makin test in order to fill a range with values but get
ComException Error when trying to set the result. ("Exception from
HRESULT: 0x800A03EC.")

Can someone tell me what I'm doing wrong ?
Thks for help.

*****

Try
Dim numberOfRows As Integer = 10
Dim numberOfColumns As Integer = 10
Dim theValues(10, 10) As Object

For i As Integer = 0 To i < numberOfRows
For j As Integer = 0 To j < numberOfColumns
theValues(i, j) = i * j
Next
Next

oExcel = CType(applicationObject, Excel.Application)
Dim theRange As Excel.Range = oExcel.Range("A1", "J10")
theRange.Value2 = theValues <- HERE IS THE ERROR
Catch ex As Exception

End Try
 
C

Cindy M -WordMVP-

Hi Franck,

I do see one logical error in what you're doing. Arrays are
zero-based. You're declaring the array with 10,10 - that means it
will have 11 by 11 elements. But the range you're specifying in
Excel is just 10 by 10.
I'm just makin test in order to fill a range with values but get
ComException Error when trying to set the result. ("Exception from
HRESULT: 0x800A03EC.")

Can someone tell me what I'm doing wrong ?
Thks for help.

*****

Try
Dim numberOfRows As Integer = 10
Dim numberOfColumns As Integer = 10
Dim theValues(10, 10) As Object

For i As Integer = 0 To i < numberOfRows
For j As Integer = 0 To j < numberOfColumns
theValues(i, j) = i * j
Next
Next

oExcel = CType(applicationObject, Excel.Application)
Dim theRange As Excel.Range = oExcel.Range("A1", "J10")
theRange.Value2 = theValues <- HERE IS THE ERROR
Catch ex As Exception

End Try

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
F

Franck

The point is that (Ok for the zero based thing ^^) it works ifd I use
automation object in a winapp.

But in my addin, it fails -
 
C

Cindy M -WordMVP-

Hi Franck,
The point is that (Ok for the zero based thing ^^) it works ifd I use
automation object in a winapp.

But in my addin, it fails -
Yes, but your winapp wouldn't be trying to fill an Excel range, would
it? And I'm thinking this is the problem: you've defined an array with
11 x 11 elements and are trying to put it into a range that's only 10 x
10.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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