Delete Method

Delete method as it applies to the Cell and Cells objects.

Deletes a table cell or cells and optionally controls how the remaining cells are shifted.

expression.Delete(ShiftCells)

expression Required. An expression that returns one of the above objects.

WdDeleteCells

WdDeleteCells can be one of these WdDeleteCells constants.
wdDeleteCellsEntireColumn
wdDeleteCellsEntireRow
wdDeleteCellsShiftLeft
wdDeleteCellsShiftUp

Delete method as it applies to the Range and Selection objects.

Deletes the specified number of characters or words. This method returns a Long value that indicates the number of items deleted, or it returns 0 (zero) if the deletion was unsuccessful.

expression.Delete(Unit, Count)

expression Required. An expression that returns one of the above objects.

Unit   Optional Variant. The unit by which the collapsed range or selection is to be deleted. Can be one of the following WdUnits constants: wdCharacter (default) or wdWord.

Count   Optional Variant. The number of units to be deleted. To delete units after the range or selection, collapse the range or selection and use a positive number. To delete units before the range or selection, collapse the range or selection and use a negative number.

Delete method as it applies to the ShapeNodes object.

Deletes the specified object.

expression.Delete(Index)

expression Required. An expression that returns a ShapeNodes object.

Index   Required Long. The number of the shape node to delete.

Delete method as it applies to all other objects in the Applies To list.

Deletes the specified object.

expression.Delete

expression Required. An expression that returns one of the objects in the Applies To list.

Example

As it applies to the Cell object.

This example deletes the first cell in the first table of the active document.

Sub DeleteCells()
    Dim intResponse As Integer

    intResponse = MsgBox("Are you sure you want " & _
        "to delete the cells?", vbYesNo)
    
    If intResponse = vbYes Then
        ActiveDocument.Tables(1).Cell(1, 1).Delete
    End If
End Sub

As it applies to the Range and Selection objects.

This example selects and deletes the contents of the active document.

Sub DeleteSelection()
    Dim intResponse As Integer
    
    intResponse = MsgBox("Are you sure you want to " & _
        "delete the contents of the document?", vbYesNo)
    
    If intResponse = vbYes Then
        ActiveDocument.Content.Select
        Selection.Delete
    End If
End Sub

As it applies to the Bookmark object.

If a bookmark named "temp" exists in the active document, this example deletes the bookmark.

Sub DeleteBookmark()
    Dim intResponse As Integer
    Dim strBookmark As String
    
    strBookmark = "temp"
    
    intResponse = MsgBox("Are you sure you want to delete " _
        & "the bookmark named """ & strBookmark & """?", vbYesNo)
    
    If intResponse = vbYes Then
        If ActiveDocument.Bookmarks.Exists(Name:=strBookmark) Then
            ActiveDocument.Bookmarks(Index:=strBookmark).Delete
        End If
    End If
End Sub

Applies to | AddIn Object | AutoCorrectEntry Object | AutoTextEntry Object | Bookmark Object | CaptionLabel Object | Cell Object | Cells Collection Object | Column Object | Columns Collection Object | Comment Object | CustomLabel Object | CustomProperty Object | DiagramNode Object | Dictionary Object | Editor Object | EmailSignatureEntry Object | Endnote Object | Field Object | FirstLetterException Object | Footnote Object | FormField Object | Frame Object | Frames Collection Object | Frameset Object | HangulAndAlphabetException Object | HeadingStyle Object | HTMLDivision Object | Hyperlink Object | Index Object | InlineShape Object | ListEntry Object | MailMergeField Object | MailMessage Object | OtherCorrectionsException Object | PageNumber Object | Range Object | RecentFile Object | Row Object | Rows Collection Object | Selection Object | Shape Object | ShapeNodes Collection Object | ShapeRange Collection Object | SmartTag Object | Style Object | StyleSheet Object | Subdocument Object | Subdocuments Collection Object | Table Object | TableOfAuthorities Object | TableOfContents Object | TableOfFigures Object | TwoInitialCapsException Object | Variable Object | Version Object | XMLNamespace Object | XMLNode Object | XMLSchemaReference Object | XSLTransform Object

See Also | Clear Method | Disable Method | Installed Property | Unload Method