views:

893

answers:

4

Hi there,

I'm trying to read the ActiveCell from within an Excel Add-in but not getting very far. Anyone any ideas?

Excel.Window W = this.Application.ActiveWindow as Excel.Window;
Excel.Range R = W.ActiveCell as Excel.Range;
MessageBox.Show(R.Value2.ToString());

The Exception being thrown on the last line is: -

Cannot obtain fields or call methods on the instance of type 'Microsoft.Office.Interop.Excel.Range' because it is a proxy to a remote object.

I tried .Value, and it says: -

Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.Excel.Range.get_Value(object)' or 'Microsoft.Office.Interop.Excel.Range.set_Value(object, object)'

On trying get_Value() I get the initial Exception again.

Cannot obtain fields or call methods on the instance of type 'Microsoft.Office.Interop.Excel.Range' because it is a proxy to a remote object.

Any ideas?

Cheers,

Phil.

A: 

Do you tried R.Value ?

liya
Modified my question to cover this case, sadly no.
Plip
A: 

Is this of any use: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f21c7cf4-fbfd-4496-a593-781eb751d580

It suggests turning off proxies for debugging purposes, hinting that the error message you are seeing may be masking a lower level COM error.

Stuart Davies
+3  A: 

R.Text.ToString(); will get you the text from the cell

holytshirt
A: 

Do not use Activewindow. modified your code as follows Excel.Range R = this.Application.ActiveCell as Excel.Range; if (R != null) MessageBox.Show(R.Value2);

Note: ActiveCell can be null if user have not chosen a cell in the active sheet.

mas_oz2k1