ComException error filling excel range with values

May 18th, 2005 - 03:49 am ET by Franck | Report spam
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
email Follow the discussionReplies 3 repliesReplies Make a reply

Similar topics

Replies

#1 Cindy M -WordMVP-
May 18th, 2005 - 06:09 am ET | Report spam
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 :-)
Replies Reply to this message
#2 Franck
May 18th, 2005 - 08:16 am ET | Report spam
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 -
Replies Reply to this message
#3 Cindy M -WordMVP-
May 20th, 2005 - 08:45 am ET | Report spam
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 :-)
email Follow the discussion Replies Reply to this message
Help Create a new topicReplies Make a reply
Search Make your own search