Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Add NamedRange Controls to Worksheets

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

  • Microsoft Office 2003

There are several ways to add NamedRange controls to your Microsoft Office Excel 2003 worksheets.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

  • From within Excel.

    You can add the NamedRange control to your worksheet in the same manner you would add the named range from within the application. The advantage of adding it this way is that you can name your control at the time you create it.

  • From the Visual Studio Toolbox.

    You can drag the NamedRange control from the Toolbox to your document. You might want to choose this way if you are already using the Toolbox to add Windows Forms controls to your document.

  • From the Data Sources Window.

    You can drag the NamedRange control to your document from the Data Sources window. This is useful when you want to bind the control to data at the time of creation of the control. You can add the host control in the same way you would add a Windows Form control from the Data Sources window. For more information, see Data Binding and Windows Forms.

  • Programmatically.

    You can add the NamedRange control programmatically. This enables you to create the host controls in response to events. Dynamically created named ranges are not persisted in the document as host controls when the document is closed. For more information, see Adding Controls to Office Documents at Run Time.

To add a NamedRange control to a worksheet using the Name Box in Excel

  1. Select the cell or cells you want to include in the named range.

  2. In the Name Box, type a name for the range and press ENTER.

    The Name Box is located to the left of the formula bar, just above column A of the worksheet.

To add a NamedRange control to a worksheet using the Toolbox

  1. Open the Toolbox and click the Excel Controls tab.

  2. Click NamedRange and drag it to a worksheet.

    The Add Named Range dialog box appears.

  3. Select the cell or cells you want to include in the named range.

  4. Click OK.

    If you do not want the default name given to the control, you can change the name in the Properties window.

You can also programmatically add controls to a worksheet. In the example below, a NamedRange control is added to cell A1 in the Startup event handler of Sheet1.

To add a NamedRange control to a worksheet programmatically

  • In the Startup event handler of Sheet1, insert the following code to add the NamedRange control to cell A1 and set its Value2 property to Hello world!

    Microsoft.Office.Tools.Excel.NamedRange textInCell;
    textInCell = this.Controls.AddNamedRange(this.get_Range("A1", missing), "cellText");
    
    textInCell.Value2 = "Hello world!";
    
    

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft