1

I would like to create a Named Range in Excel from a NetOffice, but I cannot figure out how to invoke the method. Whatever the input, the underlying Excel Object throws a COMException with a generic HRESULT 0x800A03EC Error.

  • Excel version Office 365, 16.0.13001, 64 bits
  • NetOfficeFw package, version 1.7.4.11

I have no hint about what is wrong (syntax? Excel version? NetOffice version?).Is there a known bug on this method?

Thanks for your help!

    private void CreateNameRange(Workbook wb, Range range)
    {
        try
        {
            Name existingName = (Name)wb.Names.FirstOrDefault(); //works fine if a name already exists in Excel

            wb.Names.Add(); //throws
            wb.Names.Add("name1"); //throws
            wb.Names.Add("name1", range); //throws
            wb.Names.Add("name1", range.Address); //throws
            wb.Names.Add("name1", "F7"); //throws
            wb.Names.Add("myName", "=Sheet1!$F$7:$I$13"); //throws
            wb.Names.Add("myName", "'=Sheet1!$F$7:$I$13'"); //throws

            if (_wb.ActiveSheet is Worksheet ws) {
                ws.Names.Add("myname", "=Sheet1!$F$7:$I$13");  //throws as well
            }
        }
        catch (COMException e)
        {
            //always ends up here with Inner Exception : COMException (HRESULT 0x800A03EC)
        }
    }

1 Answer 1

1

Actually, the root cause of this issue was not the method itself, but when the method was called.

I was trying to create Named Ranges from within a UDF Function but Excel considers this operation as unauthorized, along with other worksheet/data manipulation when calculation is being made, and that's why the COM Exception was raised.

Bottom line : Named Ranges cannot be created when a workbook calculation is in progress.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.