Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updated Excel Cell value by Name Reference in C#

Tags:

c#

excel

interop

I have a named cell in excel lets say its called "myCell" In C# I wish to be able to access this cell and update its value. I've tried

Globals.ThisAddIn.Application.Names.Item(@"myCell").Value = "myValue";

But this throws a COM exception with the message 'Exception from HRESULT: 0x800A03EC'

like image 549
Eddie Avatar asked Mar 10 '26 16:03

Eddie


1 Answers

Your problem is that:

Globals.ThisAddIn.Application.Names.Item(@"myCell")

does not return a Range for which you can set the value, but an object of type Name. You can get the Range representing the cell you are looking for using the RefersToRange property and then set the value for this object. This all translates into something like this:

Globals.ThisAddIn.Application.Names.Item(@"myCell").RefersToRange.Value = "myValue";
like image 58
Francesco Baruchelli Avatar answered Mar 12 '26 07:03

Francesco Baruchelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!