Hi, is there any function which can clean all ‘unused’ named ranges safely? For example, i would like to clean all named ranges which is not reference in the same workbook?
_workbook.Worksheets.Names.Clear(); … this also clean the name which is refereed to … so not suitable.
Thanks for your query.
I think you may check if a named range is referenced or not using Name.IsReferred Boolean attribute, see the sample code segment for your rerference:
e.g
Sample code:
.......
NameCollection names = workbook.Worksheets.Names;
int i = names.Count - 1;
while (i >= 0)
{
if (!names[i].IsReferred)
{
names.RemoveAt(i);
}
i--;
........
Hope, this helps a bit.