selection Property

       

Returns an IHTMLSelectionObject object that represents the current user selection. The IHTMLSelectionObject object contains methods, such as the clear method, that allows you to clear the selected items.

expression.selection

expression   Required. An expression that returns a DispFPHTMLDocument object.

Example

The following example returns the current user selection and stores it in a variable called objSelection. If the selection is type Text, it is deleted using the clear method. If the selection is not text, the selection is emptied using the empty method.

Sub Selection()
'Returns a selection and clears it if is type text

    Dim objApp As FrontPage.Application
    Dim objSelection As IHTMLSelectionObject

    Set objApp = FrontPage.Application
    Set objSelection = objApp.ActiveDocument.Selection
    'Clear the selected area of text
    If objSelection.Type = "Text" Then
       objSelection.Clear
    Else
       'Otherwise empty selection
       objSelection.empty
    End If
End Sub