Class Selection (Word VBA)
The class Selection represents the current selection in a window or pane. A selection represents either a selected (or highlighted) area in the document, or it represents the insertion point if nothing in the document is selected. There can be only one Selection object per document window pane, and only one Selection object in the entire application can be active.
The classes Application, Pane and Window. give access to class Selection
Dim slc as Selection
Set slc = Selection
Methods
BoldRun - Adds the bold character format to or removes it from the current run.
Calculate - Calculates a mathematical expression within a selection. Returns the result as a Single.
ClearCharacterAllFormatting - Removes all character formatting (formatting applied either through character styles or manually applied formatting) from the selected text.
ClearCharacterDirectFormatting - Removes character formatting (formatting that has been applied manually using the buttons on the ribbon or through the dialog boxes) from the selected text.
ClearCharacterStyle - Removes character formatting that has been applied through character styles from the selected text.
ClearFormatting - Removes text and paragraph formatting from a selection.
ClearParagraphAllFormatting - Removes all paragraph formatting (formatting applied either through paragraph styles or manually applied formatting) from the selected text.
ClearParagraphDirectFormatting - Removes paragraph formatting that has been applied manually (using the buttons on the ribbon or through the dialog boxes) from the selected text.
ClearParagraphStyle - Removes paragraph formatting that has been applied through paragraph styles from the selected text.
Collapse - Collapses a selection to the starting or ending position. After a selection is collapsed, the starting and ending points are equal.
ConvertToTable - Converts text within a range to a table. Returns the table as a Table object.
Copy - Copies the specified selection to the Clipboard.
CopyAsPicture - The CopyAsPicture method works the same way as the Copy method.
CopyFormat - Copies the character formatting of the first character in the selected text.
CreateAutoTextEntry - Adds a new AutoTextEntry object to the AutoTextEntries collection, based on the current selection.
CreateTextbox - Adds a default-size text box around the selection.
Cut - Removes the specified object from the document and moves it to the Clipboard.
Delete - Deletes the specified number of characters or words.
DetectLanguage - Analyzes the specified text to determine the language that it is written in.
EndKey - Moves or extends the selection to the end of the specified unit.
EndOf - Moves or extends the ending character position of a range or selection to the end of the nearest specified text unit.
EscapeKey - Cancels a mode such as extend or column select (equivalent to pressing the ESC key).
Expand - Expands the specified range or selection. Returns the number of characters added to the range or selection.
ExportAsFixedFormat - Saves the current selection as PDF or XPS format.
ExportAsFixedFormat2 - Saves the current selection as PDF or XPS format.
Extend - Turns on extend mode, or if extend mode is already on, extends the selection to the next larger unit of text.
GoTo - Moves the insertion point to the character position immediately preceding the specified item, and returns a Range object (except for the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant).
GoToEditableRange - Returns a Range object that represents an area of a document that can be modified by the specified user or group of users.
GoToNext - Returns a Range object that refers to the start position of the next item or location specified by the What argument. If you apply this method to the Selection object, the method moves the selection to the specified item (except for the wdGoToGrammaticalError, wdGoToProofreadingError, and wdGoToSpellingError constants).
GoToPrevious - Returns a Range object that refers to the start position of the previous item or location specified by the What argument. If applied to a Selection object, GoToPrevious moves the selection to the specified item. Range object.
HomeKey - Moves or extends the selection to the beginning of the specified unit. This method returns an integer that indicates the number of characters the selection was actually moved, or it returns 0 (zero) if the move was unsuccessful.This method corresponds to functionality of the HOME key.
InRange - True if the selection to which the method is applied is contained within the range specified by the Range argument.
InsertAfter - Inserts the specified text at the end of a range or selection.
InsertBefore - Inserts the specified text before the specified selection.
InsertBreak - Inserts a page, column, or section break.
InsertCaption - Inserts a caption immediately preceding or following the specified selection.
InsertCells - Adds cells to an existing table.
InsertColumns - Inserts columns to the left of the column that contains the selection.
InsertColumnsRight - Inserts columns to the right of the current selection.
InsertCrossReference - Inserts a cross-reference to a heading, bookmark, footnote, or endnote, or to an item for which a caption label is defined (for example, an equation, figure, or table).
InsertDateTime - Inserts the current date or time, or both, either as text or as a TIME field.
InsertFile - Inserts all or part of the specified file.
InsertFormula - Inserts an = (Formula) field that contains a formula at the selection.
InsertNewPage - Inserts a new page at the position of the Insertion Point.
InsertParagraph - Replaces the specified selection with a new paragraph.
InsertParagraphAfter - Inserts a paragraph mark after a selection.
InsertParagraphBefore - Inserts a new paragraph before the specified selection or range.
InsertRows - Inserts the specified number of new rows above the row that contains the selection. If the selection isn't in a table, an error occurs.
InsertRowsAbove - Inserts rows above the current selection.
InsertRowsBelow - Inserts rows below the current selection.
InsertStyleSeparator - Inserts a special hidden paragraph mark that allows Microsoft Word to join paragraphs formatted using different paragraph styles, so lead-in headings can be inserted into a table of contents.
InsertSymbol - Inserts a symbol in place of the specified selection.
InsertXML - Inserts the specified XML into the document at the cursor, replacing any selected text.
InStory - True if the selection to which this method is applied is in the same story as the range specified by the Range argument.
IsEqual - True if the selection to which this method is applied is equal to the range specified by the Range argument.
ItalicRun - Adds the italic character format to or removes it from the current run.
LtrPara - Sets the reading order and alignment of the specified paragraphs to left-to-right.
LtrRun - Sets the reading order and alignment of the specified run to left-to-right.
Move - Collapses the specified selection to its start or end position and then moves the collapsed object by the specified number of units. This method returns a Long value that represents the number of units by which the selection was moved, or it returns 0 (zero) if the move was unsuccessful.
MoveDown - Moves the selection down and returns the number of units it has been moved.
MoveEnd - Moves the ending character position of a range or selection.
MoveEndUntil - Moves the end position of the specified selection until any of the specified characters are found in the document.
MoveEndWhile - Moves the ending character position of a selection while any of the specified characters are found in the document.
MoveLeft - Moves the selection to the left and returns the number of units it has been moved.
MoveRight - Moves the selection to the right and returns the number of units it has been moved.
MoveStart - Moves the start position of the specified selection.
MoveStartUntil - Moves the start position of the specified selection until one of the specified characters is found in the document. If the movement is backward through the document, the selection is expanded.
MoveStartWhile - Moves the start position of the specified selection while any of the specified characters are found in the document.
MoveUntil - Moves the specified selection until one of the specified characters is found in the document.
MoveUp - Moves the selection up and returns the number of units that it has been moved.
MoveWhile - Moves the specified selection while any of the specified characters are found in the document.
Next - Returns a Range object that represents the next unit relative to the specified selection.
NextField - Selects the next field.
NextRevision - Locates and returns the next tracked change as a Revision object.
NextSubdocument - Moves the selection to the next subdocument.
Paste - Inserts the contents of the Clipboard at the specified selection.
PasteAndFormat - Pastes the selected table cells and formats them as specified.
PasteAppendTable - Merges pasted cells into an existing table by inserting the pasted rows between the selected rows. No cells are overwritten.
PasteAsNestedTable - Pastes a cell or group of cells as a nested table into the selection.
PasteExcelTable - Pastes and formats a Microsoft Excel table.
PasteFormat - Applies formatting copied with the CopyFormat method to the selection.
PasteSpecial - Inserts the contents of the Clipboard.
Previous - Moves the selected text by the specified number of units, and returns a Range object relative to the collapsed selection.
PreviousField - Selects and returns the previous field.
PreviousRevision - Locates and returns the previous tracked change as a Revision object.
PreviousSubdocument - Moves the selection to the previous subdocument.
ReadingModeGrowFont - Increases the size of the displayed text one point size when the document is displayed in Reading mode.
ReadingModeShrinkFont - Decreases the size of the displayed text one point size when the document is displayed in Reading mode.
RtlPara - Sets the reading order and alignment of the specified paragraphs to right-to-left.
RtlRun - Sets the reading order and alignment of the specified run to right-to-left.
Select - Selects the specified text.
SelectCell - Selects the entire cell containing the current selection.
SelectColumn - Selects the column that contains the insertion point, or selects all columns that contain the selection.
SelectCurrentAlignment - Extends the selection forward until text with a different paragraph alignment is encountered.
SelectCurrentColor - Extends the selection forward until text with a different color is encountered.
SelectCurrentFont - Extends the selection forward until text in a different font or font size is encountered.
SelectCurrentIndent - Extends the selection forward until text with different left or right paragraph indents is encountered.
SelectCurrentSpacing - Extends the selection forward until a paragraph with different line spacing is encountered.
SelectCurrentTabs - Extends the selection forward until a paragraph with different tab stops is encountered.
SelectRow - Selects the row that contains the insertion point, or selects all rows that contain the selection.
SetRange - Sets the starting and ending character positions for the selection.
Shrink - Shrinks the selection to the next smaller unit of text.
ShrinkDiscontiguousSelection - Cancels the selection of all but the most recently selected text when a selection contains multiple, unconnected selections.
Sort - Sorts the paragraphs in the specified selection.
SortAscending - Sorts paragraphs or table rows in ascending alphanumeric order.
SortByHeadings - Sorts the headings in the specified selection.
SortDescending - Sorts paragraphs or table rows within the selection in descending alphanumeric order.
SplitTable - Inserts an empty paragraph above the first row in the selection.
StartOf - Moves or extends the start position of the specified range or selection to the beginning of the nearest specified text unit. This method returns a Long that indicates the number of characters by which the range or selection was moved or extended. The method returns a negative number if the movement is backward through the document.
ToggleCharacterCode - Switches a selection between a Unicode character and its corresponding hexadecimal value.
TypeBackspace - Deletes the character preceding a collapsed selection (an insertion point).
TypeParagraph - Inserts a new, blank paragraph.
TypeText - Inserts the specified text.
WholeStory - Expands a selection to include the entire story.
Properties
Text (Default member) - Returns or sets the text in the specified selection.
Active true if the selection in the specified window or pane is active.
BookmarkID returns the number of the bookmark that encloses the beginning of the specified selection.
Bookmarks returns a Bookmarks collection that represents all the bookmarks in a document, range, or selection.
Borders returns a Borders collection that represents all the borders for the specified object.
Cells returns a Cells collection that represents the table cells in a selection.
Characters returns a Characters collection that represents the characters in a document, range, or selection.
ChildShapeRange returns a ShapeRange collection representing the child shapes contained within a selection.
Columns returns a Columns collection that represents all the table columns in a selection.
ColumnSelectMode true if column selection mode is active.
Comments returns a Comments collection that represents all the comments in the specified.
Document returns a Document object associated with the specified selection.
Editors returns an Editors object that represents all the users authorized to modify a selection within a document.
End returns or sets the ending character position of a selection.
EndnoteOptions returns an EndnoteOptions object that represents the endnotes in a selection.
Endnotes returns an Endnotes collection that represents all the endnotes contained within a selection.
EnhMetaFileBits returns a Variant that represents a picture representation of how a selection or range of text appears.
ExtendMode true if Extend mode is active.
Fields returns a read-only Fields collection that represents all the fields in the selection.
Find returns a Find object that contains the criteria for a find operation.
FitTextWidth returns or sets the width (in the current measurement units) in which Microsoft Word fits the text in the current selection.
Flags returns or sets properties of the selection.
Font returns or sets a Font object that represents the character formatting of the specified object.
FootnoteOptions returns FootnoteOptions object that represents the footnotes in a selection.
Footnotes returns a Footnotes collection that represents all the footnotes in a range, selection, or document.
FormattedText returns or sets a Range object that includes the formatted text in the specified range or selection.
FormFields returns a FormFields collection that represents all the form fields in the selection.
Frames returns a Frames collection that represents all the frames in a selection.
HasChildShapeRange true if the selection contains child shapes.
HeaderFooter returns a HeaderFooter object for the specified selection.
HTMLDivisions returns an HTMLDivisions object that represents an HTML division in a web document.
Hyperlinks returns a Hyperlinks collection that represents all the hyperlinks in the specified selection.
Information returns information about the specified selection.
InlineShapes returns an InlineShapes collection that represents all the InlineShape objects in a selection.
IPAtEndOfLine true if the insertion point is at the end of a line that wraps to the next line.
IsEndOfRowMark true if the specified selection or range is collapsed and is located at the end-of-row mark in a table.
LanguageDetected returns or sets a Boolean that specifies whether Microsoft Word has detected the language of the selected text.
LanguageID returns or sets the language for the specified object.
LanguageIDFarEast returns or sets an East Asian language for the specified object.
LanguageIDOther returns or sets the language for the specified object.
NoProofing true if the spelling and grammar checker ignores the specified text. Returns wdUndefined if the NoProofing property is set to True for only some of the specified text.
OMaths returns an OMaths collection that represents the OMath objects within the current selection.
Orientation returns or sets the orientation of text in a selection when the Text Direction feature is enabled.
PageSetup returns a PageSetup object that's associated with the specified selection.
ParagraphFormat returns or sets a ParagraphFormat object that represents the paragraph settings for the specified selection.
Paragraphs returns a Paragraphs collection that represents all the paragraphs in the specified selection.
PreviousBookmarkID returns the number of the last bookmark that starts before or at the same place as the specified selection or range; returns 0 (zero) if there is no corresponding bookmark.
Range returns a Range object that represents the portion of a document that's contained in the specified object.
Rows returns a Rows collection that represents all the table rows in a range, selection, or table.
Sections returns a Sections collection that represents the sections in the specified selection.
Sentences returns a Sentences collection that represents all the sentences in the selection.
Shading returns a Shading object that refers to the shading formatting for the specified selection.
ShapeRange returns a ShapeRange collection that represents all the Shape objects in the selection.
Start returns or sets the starting character position of a selection.
StartIsActive true if the beginning of the selection is active.
StoryLength returns the number of characters in the story that contains the specified selection.
StoryType returns the story type for the specified selection.
Style returns or sets the style for the specified style. To set this property, specify the local name of the style, an integer, a WdBuiltinStyle constant, or an style that represents the style. For a list of valid constants, consult the Microsoft Visual Basic style Browser. Read/write Variant.
Tables returns a Tables collection that represents all the tables in the specified selection.
TopLevelTables returns a Tables collection that represents the tables at the outermost nesting level in the current selection.
Type returns the selection type.
WordOpenXML returns a String that represents the XML contained within the selection in the Microsoft Word Open XML format.
Words returns a Words collection that represents all the words in a selection.
XML returns a String that represents the XML text in the specified object.
Related Classes
AutoTextEntry - Represents a single AutoText entry. The AutoTextEntry object is a member of the AutoTextEntries collection. The AutoTextEntries collection contains all the AutoText entries in the specified template. The entries are listed on the AutoText tab in the AutoCorrect dialog box.
Bookmarks - A collection of Bookmark objects that represent the bookmarks in the specified selection, range, or document.
Borders - A collection of Border objects that represent the borders of an object.
Cells - A collection of Cell objects in a table column, table row, selection, or range.
Characters - A collection of characters in a selection, range, or document. There is no Character object; instead, each item in the Characters collection is a Range object that represents one character.
Columns - A collection of Column objects that represent the columns in a table.
Comments - A collection of Comment objects that represent the comments in a selection, range, or document.
Document - Represents a document. The Document object is a member of the Documents collection. The Documents collection contains all the Document objects that are currently open in Word.
Editors - A collection of Editor objects that represents a collection of users or groups of users who have been given specific permissions to edit portions of a document.
EndnoteOptions - Represents the properties assigned to a range or selection of endnotes in a document.
Endnotes - A collection of Endnote objects that represents all the endnotes in a selection, range, or document.
Field - Represents a field. The Field object is a member of the Fields collection. The Fields collection represents the fields in a selection, range, or document.
Fields - A collection of Field objects that represent all the fields in a selection, range, or document.
Find - Represents the criteria for a find operation.
Font - Contains font attributes (such as font name, font size and color) for an object.
FootnoteOptions - Represents the properties assigned to a range or selection of footnotes in a document.
Footnotes - A collection of Footnote objects that represent all the footnotes in a selection, range, or document.
FormFields - A collection of FormField objects that represent all the form fields in a selection, range, or document.
Frames - Word Object Model Reference
HeaderFooter - Represents a single header or footer. The HeaderFooter object is a member of the HeadersFooters collection. The HeadersFooters collection includes all headers and footers in the specified document section.
HTMLDivisions - A collection of HTMLDivision objects that represents the HTML DIV elements that exist in a web document.
Hyperlinks - Represents the collection of Hyperlink objects in a document, range, or selection.
InlineShapes - A collection of InlineShape objects that represent all the inline shapes in a document, range, or selection.
OMaths - A collection of equations. Use the OMath object to access individual members of the collection.
PageSetup - Represents the page setup description. The PageSetup object contains all the page setup attributes of a document (such as left margin, bottom margin, and paper size) as properties.
ParagraphFormat - Represents all the formatting for a paragraph.
Paragraphs - A collection of Paragraph objects in a selection, range, or document.
Range - Represents a contiguous area in a document. Each Range object is defined by a starting and ending character position.
Revision - Represents a change marked with a revision mark. The Revision object is a member of the Revisions collection. The Revisions collection includes all the revision marks in a range or document.
Rows - A collection of Row objects that represent the table rows in the specified selection, range, or table.
Sections - A collection of Section objects in a selection, range, or document.
Sentences - A collection of Range objects that represent all the sentences in a selection, range, or document. There is no Sentence object.
Shading - Contains shading attributes for an object.
ShapeRange - Represents a shape range, which is a set of shapes on a document. A shape range can contain as few as one shape or as many as all the shapes in the document.
Style - Represents a single built-in or user-defined style. The Style object includes style attributes (such as font, font style, and paragraph spacing) as properties of the Style object. The Style object is a member of the Styles collection. The Styles collection includes all the styles in the specified document.
Table - Represents a single table. The Table object is a member of the Tables collection. The Tables collection includes all the tables in the specified selection, range, or document.
Tables - A collection of Table objects that represent the tables in a selection, range, or document.
Words - A collection of words in a selection, range, or document. Each item in the Words collection is a Range object that represents one word. There is no Word object.