selection 属性

       

返回 IHTMLSelectionObject 对象,该对象代表当前用户所选的内容。IHTMLSelectionObject 对象包含方法,例如,允许您清除所选项目的 clear 方法。

expression.selection

expression  必选。返回 DispFPHTMLDocument 对象的表达式。

示例

下列示例返回当前用户所选的内容,并将其存储在称为 objSelection 的变量中。如果所选内容是 Text 类型,则可以使用 clear 方法将其删除。如果所选内容不是 Text 类型,则可以使用 empty 方法将其清空。

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