I have been trying to delete defined names in Excel 2010 from a converted Excel 97-2003 workbook. I have unprotected the sheets programmatically and called the delete function on the items in question. No errors it just does not delete. Here is some of the code...
var ranges = xlApp.ActiveWorkbook.Names;
for (int k = 1; k < ranges.Count; k++)
{
var currentName = ranges.Item(k, oMissing, oMissing);
var refersTo = currentName.RefersTo.ToString();
if (refersTo.Contains("REF!"))
{
ranges.Item(k, oMissing, oMissing).Delete();
}
}
tmpWrkBook.Save();
var ranges = xlApp.ActiveWorkbook.Names;
for (int k = 1; k < ranges.Count; k++)
{
var currentName = ranges.Item(k, oMissing, oMissing);
var refersTo = currentName.RefersTo.ToString();
if (refersTo.Contains("REF!"))
{
ranges.Item(k, oMissing, oMissing).Delete();
}
}
tmpWrkBook.Save();