Question

I'm using VSTO (on Visual Studio 2008 due to a client request) to create Named ranges on single cells, which are then saved to the workbook and subsequently read when the application restarts.

If I delete a row containing one or more named ranges in excel, save my workbook and restart excel, the named ranges in said row are still returned, and this is causing my problem.

In order to name the cells, I am does a simple Application.Selection.Name = "whatever". And to get them back upon starup I am using Application.ActiveWorkbook.Names.

Can somebody please tell me if this is correct behaviour, and if so if there is any way to filter ranges - via the C# excel interop code - to only ones that are currently visible.

Thanks in advance.

Was it helpful?

Solution

Yes, this is correct behaviour, and it is not related to VSTO.

When you delete a range that had a name, the name is not deleted. Instead, it is replaced with an invalid reference:

Sheet1!#REF!  

The easiest way to detect such names is capturing exception when reading the RefersToRange property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top