Range.setValue() causes "Exception from HRESULT: 0x800A03EC"

D

deverard

I am attempting to write data retrieved from a web service to a range of
cells in an Excel worksheet using the Office Interop library. My code is
based upon the MSDN KB code example at
http://support.microsoft.com/kb/302096, and uses the Range.set_value method.
THis code snippet is simply trying to copy the contents of a range to the
target destination at $A$1:


targetRange = ExcelSessionProvider.ActiveSheet.get_Range("$A$1", missing);

int xSize = ((object[,])rangeName.Value2).GetLength(0);
int ySize = ((object[,])rangeName.Value2).GetLength(1);

targetRange = targetRange.get_Resize(xSize, ySize);

// Create an array.
object[,] saRet = new object[xSize, ySize];

// Fill the array.
for (int iRow = 0; iRow < xSize; iRow++)
{
for (int iCol = 0; iCol < ySize; iCol++)
{
//Put data in the cell.
saRet[iRow, iCol] = ((object[,])rangeName.Value2)[iRow+1,iCol+1];
}
}

targetRange.set_Value(missing, saRet);

The exception is thrown regardless of the source range cell contents. It is
always thrown by set_Value(). The targetRange and the array (saRet) are the
same size.

Any help on this error would be greatly appreciated. I have hit a wall!

Thanks in advance.
 

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