ListObject.Delete Method

Deletes a dynamically created ListObject control, clears the cell data from the worksheet, and removes the control from the ControlCollection.

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

Syntax

'Declaration
Sub Delete
void Delete()

Remarks

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

If the list object is linked to a SharePoint site, deleting it does not affect data on the server that is running Windows SharePoint Services. Any uncommitted changes made to the local list object are not sent to the SharePoint list. (There is no warning that these uncommitted changes are lost.)

Examples

The following code example creates a ListObject on the current worksheet and then displays a message box that asks the user whether to delete the ListObject. If the user accepts, then the Delete method is called to remove the ListObject.

This example is for a document-level customization.

Private Sub ListObject_Delete()
        Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
            Me.Controls.AddListObject(Me.Range("A1", "D4"), "List1")

        If DialogResult.Yes = MessageBox.Show("Delete the ListObject?", _
            "Test", MessageBoxButtons.YesNo) Then
            List1.Delete()
        End If 

    End Sub
private void ListObject_Delete()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(this.Range["A1", "D4"], "list1");

    if (DialogResult.Yes == MessageBox.Show("Delete the ListObject?",
        "Test", MessageBoxButtons.YesNo))
    {
        list1.Delete();
    }
}

.NET Framework Security

See Also

Reference

ListObject Interface

Microsoft.Office.Tools.Excel Namespace