Remove Named ranges (Name) which have an invalid reference

What is the best practice using Aspose API to remove all named ranges with a specfic prefix which are referring #REF! (wrong reference).

i.e. remvoe all name that starts with “pre_” with invlalid reference.

Another related question is what will happen when I use Names.Remove API and the name range exists more than once (i.e. scope - Workbook and Worksheet), which name range will be deleted

@orik

You have to iterate all defined names to check whether their refers contains specfic prefix.

Please use Name.SheetIndex to check this name belongs to Workbook or Worksheet.
0 = Global name, otherwise index to sheet (one-based)

@simon.zhao - thank for your answer.
I there a clear indication that name range is referring #REF! ?

@orik,

No, apparently there is no direct option available if a named range refers to “#REF!”.

@orik
Please check whether the formula of the defined name contains “#REF!” as :

if(name.RefersTo.IndexOf("#REF!"))
            {

            }