Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Named references
posted

Hi, can you tell me how to set a named reference programmatically in a worksheet? (the equivalent of making a cell selection and typing a custom title into the Name Box in the formula bar)

Similarly if a user has set any of their own named references I'd like to be able to look at that collection, can you show me where that is.

Thanks

  • 1225
    Offline posted

    Hi Robert,
    You can add named references to the workbook referring to the two different reference modes like,

    wSheet = wBook.Worksheets.Add("First");
    wBook.NamedReferences.Add("one", "=First!$A$1", CellReferenceMode.A1);
    wBook.NamedReferences.Add("two", "=First!$A$3", CellReferenceMode.A1);
    wBook.NamedReferences.Add("square", "=First!$A$1:$A$3", CellReferenceMode.A1);
    wBook.NamedReferences.Add("square1", "=First!$B$1:$B$3", CellReferenceMode.A1);
    or
    wBook.Worksheets.Add("Second");
    wBook.CellReferenceMode = CellReferenceMode.R1C1;
    wBook.NamedReferences.Add("three", "=Second!R1C1");
    wBook.NamedReferences.Add("four", "=Second!R3C3");

    Thanks,
    Josheela