Check the existence of a named range in a worksheet without exceptions.
Try to get the named range with Evaluate. This will respond the error code -2146826259 if no named cell exists or an range object and will not throw any exception. Despite running evaluate on the worksheet it could return named cells defined for the hole workbook which are not on the given worksheet.
Thus you have to check if the returned range is on the desired worksheet.
public static bool NamedCellDefiend(Worksheet ws, string name)
i = ws.Evaluate(name);
Range xlRange = (Range)i;
bool result = xlRange.Worksheet.Equals(ws);
Get the value of a named cell exception-free.
If (NamedCellDefined(ws, "Test")
Microsoft Excel Tips · · · ·