Delete Method
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, Dictionary object, Endnote object, Field object, FirstLetterException object, Footnote object, FormField object, Frame object, Frames collection object, HeadingStyle object, Hyperlink object, Index object, InlineShape object, ListEntry object, MailMergeField object, MailMessage object, PageNumber object, Range object, RecentFile object, Row object, Rows collection object, Selection object, Shape object, ShapeNodes collection object, ShapeRange collection object, Style object, Subdocument object, Subdocuments collection object, Table object, TableOfAuthorities object, TableOfContents object, TableOfFigures object, TwoInitialCapsException object, Variable object, Version object.
Description
Syntax 1: Deletes the specified object.
Syntax 2: Deletes a table cell or cells and optionally controls how the remaining cells are shifted.
Syntax 3: Deletes the specified number of characters or words. This method returns a value that indicates the number of items deleted, or it returns 0 (zero) if the deletion was unsuccessful.
Syntax 1
expression.Delete
Syntax 2
expression.Delete(ShiftCells)
Syntax 3
expression.Delete(Unit, Count)
expression Syntax 1: Required. An expression that returns an object in the Applies To list.
Syntax 2: Required. An expression that returns a Cell or Cells object.
Syntax 3: Required. An expression that returns a Range or Selection object.
ShiftCells Optional Variant. The direction in which the remaining cells are to be shifted. Can be one of the following WdDeleteCells constants: wdDeleteCellsEntireColumn, wdDeleteCellsEntireRow, wdDeleteCellsShiftLeft, or wdDeleteCellsShiftUp.
Unit Optional Variant. The unit by which the collapsed range or selection is to be deleted. Can be either of the following WdUnits constants: wdCharacter or wdWord. The default value is wdCharacter.
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.
See Also
Clear method, Disable method, Installed property, Unload method.
Example
This example deletes the selection.
Selection.Delete
This example collapses the selection and deletes the two words following the insertion point.
Selection.Collapse Direction:=wdCollapseStart
Selection.Delete Unit:=wdWord, Count:=2
This example collapses myRange and deletes the two characters preceding the insertion point.
Set myRange = Selection.Words(1)
myRange.Collapse Direction:=wdCollapseStart
myRange.Delete Unit:=wdCharacter, Count:=-2
This example deletes the first cell in the first table in document one.
Documents(1).Tables(1).Cell(1, 1).Delete ShiftCells:=wdDeleteCellsShiftLeft
If the bookmark named "temp" exists in the active document, this example deletes the bookmark.
If ActiveDocument.Bookmarks.Exists("temp") Then
ActiveDocument.Bookmarks("temp").Delete
End If
This example deletes the style named "Intro" from Sales.doc. Paragraphs using the Intro style will revert to using the Normal style.
Documents("Sales.doc").Styles("Intro").Delete
This example deletes the first word in the active document.
ActiveDocument.Words(1).Delete