Selection Interface
Represents the current selection in a window or pane.
Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in microsoft.office.interop.word.dll)
Usage
Public Class electionImplementation
Implements Selection
End Class
Dim electionImplementation1 As New electionImplementation()
Syntax
Public Interface Selection
public interface Selection
public interface class Selection
public interface Selection
public interface Selection
Remarks
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 only be one Selection object per document window pane, and only one Selection object in the entire application can be active.
Use the Selection property to return the Selection object. If no object qualifier is used with the Selection property, Microsoft Word returns the selection from the active pane of the active document window.
The document doesn't have to be active to access its current selection.
Use the Text property to set or return the text in the current selection.
The Selection object has various methods and properties with which you can:
Collapse, expand, or otherwise change the current selection.
Edit selected text in a document.
Change the formatting of the current selection.
Use properties like Flags, Information, and Type to return information about the current selection.
Even when a selection is collapsed to an insertion point, it isn't necessarily empty. For example, the Text property will still return the character to the right of the insertion point; this character also appears in the Characters collection of the Selection object. However, calling methods like Cut or Copy from a collapsed selection will cause an error.
It's possible for the user to select a region in a document that doesn't represent contiguous text (for example, when using the ALT key with the mouse). Because the behavior of such a selection can be unpredictable, you may want to include a step in your code that checks the Type property of a selection before performing any operations on it. Similarly, selections that include table cells can also lead to unpredictable behavior. The Information property will tell you if a selection is inside a table.
Because Range objects share many of the same methods and properties as Selection objects, using Range objects is preferable for manipulating a document when there isn't a reason to physically change the current selection.
Platforms
Development Platforms
Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000
Target Platforms
See Also
Reference
Microsoft.Office.Interop.Word Namespace