NamedRange Control

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Document-level projects

  • Excel 2007

  • Excel 2003

Application-level projects

  • Excel 2007

For more information, see Features Available by Application and Project Type.

The NamedRange control is a range that has a unique name, exposes events, and can be bound to data. For more information about ranges, see Excel Object Model Overview.

Creating the Control

You can add NamedRange controls to a Microsoft Office Excel worksheet at design time or at run time in document-level projects.

Starting in Visual Studio 2008 Service Pack 1 (SP1), you can add NamedRange controls to a worksheet at run time in an application-level add-in. For more information, see How to: Add NamedRange Controls to Worksheets.

Note

By default, dynamically created named ranges are not persisted in the worksheet as host controls when the worksheet is closed. For more information, see Adding Controls to Office Documents at Run Time.

NamedRange controls can only consist of ranges on specific sheets. NamedRange controls cannot have relative names that apply to all sheets, and they cannot consist of ranges that span two or more worksheets in a workbook (3-D ranges).

Binding Data to the Control

A named range would appear to be a good candidate for complex data binding since it can have many cells; however, a range is merely a collection of cells that cannot be easily mapped to a particular column from a dataset. Therefore, NamedRange controls only support simple data binding. The ListObject control can be used for complex data binding. For more information, see ListObject Control.

The NamedRange control can be bound to a data source using the DataBindings properties. The default data binding property of the NamedRange control is Value2.

If the data in the bound dataset is updated through any mechanism, the NamedRange control reflects the changes.

Formatting

Formatting that can be applied to a Range can be applied to a Microsoft.Office.Tools.Excel.NamedRange control. This includes borders, fonts, number format and styles.

Renaming the Control

When you add a NamedRange control to your worksheet from the Toolbox, Visual Studio Tools for Office automatically generates a name for the control. You can change the name in the Properties window.

Events

The following events are available for the NamedRange control:

See Also

Tasks

Excel Add-In Dynamic Controls Sample

How to: Add NamedRange Controls to Worksheets

How to: Delete NamedRange Controls at Design Time

How to: Resize NamedRange Controls

Walkthrough: Programming Against Events of a NamedRange Control

Concepts

Binding Data to Controls in Office Solutions

Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time

Excel Application-Level Add-in Development

Adding Controls to Office Documents at Run Time

Binding Data to Controls in Office Solutions

Programmatic Limitations of Host Items and Host Controls

Other Resources

Controls on Office Documents

Excel Host Controls

Word Host Controls

Change History

Date

History

Reason

July 2008

Added information about using NamedRange controls in application-level add-ins.

SP1 feature change.