NamedRange.Change Event (2007 System)
Updated: July 2008
Occurs when something changes in the NamedRange control.
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
This event is raised if the NamedRange control is changed by either a programmatic modification or user interaction. This event does not occur when cells in a NamedRange control change during a recalculation.
The following code example creates a NamedRange and a Change event handler. To raise the Change event, add text to one of the cells in the NamedRange and then press ENTER.
This version is for a document-level customization.
Microsoft.Office.Tools.Excel.NamedRange changesRange; private void NotifyChanges() { changesRange = this.Controls.AddNamedRange( this.Range["B2", "E5"], "compositeRange"); changesRange.Change += new Microsoft.Office.Interop.Excel. DocEvents_ChangeEventHandler(changesRange_Change); } void changesRange_Change(Excel.Range Target) { string cellAddress = Target.get_Address(missing, missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, missing, missing); MessageBox.Show("Cell " + cellAddress + " changed."); }
This version is for an application-level add-in.
NamedRange changesRange; private void NotifyChanges() { Worksheet vstoWorksheet = ((Excel.Worksheet) this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject(); changesRange = vstoWorksheet.Controls.AddNamedRange( vstoWorksheet.Range["B2", "E5"], "compositeRange"); changesRange.Change += new Excel.DocEvents_ChangeEventHandler( changesRange_Change); } void changesRange_Change(Excel.Range Target) { string cellAddress = Target.get_Address(missing, missing, Excel.XlReferenceStyle.xlA1, missing, missing); System.Windows.Forms.MessageBox.Show("Cell " + cellAddress + " changed."); }
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.