Home Page (Objects) | Overview | FAQ | Reference
Applies to: TextDocument object, TextWindow object
Gets the TextSelection object, which represents the selected text.
Syntax
object.Selection
Parameters
object
An expression that evaluates to a TextDocument object or a TextWindow object.
Remarks
The Selection property has the TextSelection type.
For the TextDocument object, the Selection property gets the object representing the text selected in a document's active view or in the topmost view if no views are active.
For the TextWindow object, the Selection property gets the object representing the text selected in the text window.
Examples
The following macro converts selected source code into a comment. In this example, note that the Text property is the default; you do not have to specify it.
Sub CommentOutSelection
MyString = ActiveDocument.Selection.Text
ActiveDocument.Selection = "/*" + MyString + "*/"
End Sub
The following macro inserts a "#include" statement followed by a line break at the beginning of the active document.
Sub AddWindowsInclude
ActiveWindow.Selection.StartOfDocument
ActiveWindow.Selection = "#include <windows.h>" + vbCrLf
End Sub
For more examples of using the Selection property, see the samples in Sample.dsm, which is in the Developer Studio \Macros directory.