interop >> Range offsets and #VALUE! error

by c.m.valdivia » Fri, 05 May 2006 03:55:01 GMT

I'm new to making Automation Add-ins for Excel so this may be
trivial...

I'm trying to create an Excel offset function (using Automation) that
takes
an offset in rows and columns and a value and prints that value in the
offset
cell and the cell from which the function is called. I can get one or
the
other, but not both. When I set the off set cell's Value2 property to
the
specified value, the original cell returns a wierd #VALUE! error. This
doesn't seem right to me. Shouldn't the offSet cell display the correct
value
as a side effect of the function call and the original cell display the

correct value due to the return of the function?

My code is below, I'm developing in Visual Studio 2005 and my project
is
otherwise default. Any answers?

// test offsetting
// keep getting wierd error in selected cell
//
public double xyOffset(int xOff, int yOff, double val)
{

Excel.Application excelApp = (Excel.Application)applicationObject;
Excel.Range cell = excelApp.ActiveCell;

// testing to see how get_Offset works

Excel.Range offCell = cell.get_Offset(yOff, xOff);
// return val; // works up to this point.

// works up to this point.
// this is how set values of cells?
offCell.Value2 = val;
return val; /* At this point will display val in
* offset properly but will display #VALUE#
* in the initial selected field.
*/
}


interop >> Range offsets and #VALUE! error

by c.m.valdivia » Fri, 05 May 2006 21:58:18 GMT


Any ideas?

Similar Threads

1. index value out-of-range error

2. Error: Out of range value adjusted for column 'EngrAlertForNewQuestions' at row 1 - Asp.Net

3. Com Error when using multiple dimension array to set the value of a range

I'm trying to use a multiple dimension string array in C# (string[,]) 
to set the 'Value' attribute of a Range object.  In this particular
case the array is 1x1 and the Range is only one cell.  When the string
within the array is too large (~> 920 characters) I get a com
exception. If I use a string directly instead of an array, everything
works fine not matter how big the string is.  I'm using late binding
to make the calls but I don't think that makes any difference. Anyone
come across this problem before?

4. Error:"value does not fall within expected range" - VB.Net

5. ComException error filling excel range with values

Hi,
Working with a Shared Addin (Autodual Class implementing the
IdExtensibility2 interface), 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

6. Error Message Using CrystalReportViewer - Value Out of Range - Visual Studio .Net/VS.net

7. Error in setting value of a range

I have a sheet called Step2 and I am using the following statement

Globals.Step2.Range("A6").Value ="Test"

This used to work before with VSTO 2005 Beta 1.  I am now using Beta 2.
 I get the following error

System.Runtime.InteropServices.COMException occurred
  ErrorCode=-2146827284
  Message="Exception from HRESULT: 0x800A03EC"
  Source="Microsoft.Office.Interop.Excel"
  StackTrace:
       at Microsoft.Office.Interop.Excel._Worksheet.get_Range(Object
Cell1, Object Cell2)

When I type
?globals.Step1.Range("A1").Value
in the immediate pane I get the following response
'globals' is ambiguous, imported from the namespaces or types

Can someone please help me figure this out?

Thanks,

Sai

8. Read/Write Values at a Given Hex Address Offset - VB.Net