NamedRange.Delete Method (2007 System)

Deletes a dynamically created NamedRange control and removes it from the ControlCollection.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Sub Delete
'Usage
Dim instance As NamedRange

instance.Delete()
public void Delete()
public:
void Delete()
public function Delete()

Remarks

This method should only be used with a NamedRange control that is created programmatically at run time. An exception is thrown if you call this method on a NamedRange control that is added to the document at design time.

Examples

The following code example sets a NamedRange control that includes cells A1 through A5 to random values, and then uses the Delete method to remove the NamedRange control. Note that although the NamedRange control is deleted, cells A1 through A5 retain their values.

This example is for a document-level customization.

Private Sub DeleteRange()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
        "namedRange1")
    namedRange1.Formula = "=rand()"

    namedRange1.Delete()
End Sub
private void DeleteRange()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");
    namedRange1.Formula = "=rand()";

    namedRange1.Delete();
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace