Selection.Select 方法 (Visio)

选中或清除对象的选定内容。

语法

表达式选择 (SheetObjectSelectAction)

表达 一个代表 Selection 对象的变量。

参数

名称 必需/可选 数据类型 说明
SheetObject 必需 [IVSHAPE] 一个返回要选择或清除的 Shape 对象的表达式。
SelectAction 必需 Integer 要执行的选择动作的类型。

返回值

Nothing

注解

当用于 Window 对象时,Select 方法会对 Microsoft Visio 窗口中的选定内容产生影响。 但是,Selection 对象与该窗口中的选定内容无关。 因此,将 Select 方法用于 Selection 对象只影响内存中对象的状态,而对 Visio 窗口没有任何影响。

下列由 Visio 类型库在 VisSelectArgs 中声明的常量均显示选定类型的有效值。

常量 Description
visDeselect 1 取消选择形状,但不更改其他选择内容。
visSelect 2 选择形状但不更改其余选定内容。
visSubSelect 3 选择已选中其父形状的形状。
visSelectAll 4 选择形状及其所有对等方。
visDeselectAll 256 取消选择形状及其所有对等项。

如果 SelectActionvisSubSelect,则必须已选择了 SheetObject 的父形状。

在选择或部分选择其他形状之前,您可以先将 visDeselectAllvisSelectvisSubSelect 合并,以取消选择所有形状。

如果正在对其进行操作的对象是 Selection 对象,并且 Select 方法选择一个 Shape 对象,该对象的 ContainingShape 属性与 Selection 对象的 ContainingShape 属性不同,则 Select 方法会清除所有内容,即使选择内容类型值不指定取消选择也是如此。

如果正在对其进行操作的对象是 Window 对象,而且 SelectAction 不是 visSubSelect,则 SheetObject 的父形状必须与 Window.Selection 对象的 ContainingShape 属性返回的形状相同。

示例

以下 Microsoft Visual Basic for Applications (VBA) 宏显示如何选择、清除和部分选择形状。

 
Public Sub Select_Example() 
 
 Const MAX_SHAPES = 6 
 Dim vsoShapes(1 To MAX_SHAPES) As Visio.Shape 
 Dim intCounter As Integer 
 
 'Draw six rectangles. 
 For intCounter = 1 To MAX_SHAPES 
 Set vsoShapes(intCounter) = ActivePage.DrawRectangle(intCounter, intCounter + 1, intCounter + 1, intCounter) 
 Next intCounter 
 
 'Cancel the selection of all the shapes on the page. 
 ActiveWindow.DeselectAll 
 
 'Create a Selection object. 
 Dim vsoSelection As Visio.Selection 
 Set vsoSelection = ActiveWindow.Selection 
 
 'Select the first three shapes on the page. 
 For intCounter = 1 To 3 
 vsoSelection.Select vsoShapes(intCounter), visSelect 
 Next intCounter 
 
 'Group the selected shapes. 
 'Although the first three shapes are now grouped, the 
 'array vsoShapes() still contains them. 
 Dim vsoGroup As Visio.Shape 
 Set vsoGroup = vsoSelection.Group 
 
 'There are now four shapes on the page - a group that contains three 
 'subshapes, and three ungrouped shapes. Subselection is 
 'accomplished by selecting the parent shape first or one of the 
 'group's shapes already subselected. 
 
 'Select parent (group) shape. 
 ActiveWindow.Select vsoGroup, visDeselectAll + visSelect 
 
 'Subselect two of the shapes in the group. 
 ActiveWindow.Select vsoShapes(1), visSubSelect 
 ActiveWindow.Select vsoShapes(3), visSubSelect 
 
 'At this point two shapes are subselected, but we want to 
 'start a new selection that includes the last two shapes 
 'added to the page and the group. 
 
 'Note that the subselections that were made in the group 
 'are canceled by selecting another shape that is 
 'at the same level as the parent of the subselected shapes. 
 
 'Select just one shape. 
 ActiveWindow.Select vsoShapes(MAX_SHAPES), _ 
 visDeselectAll + visSelect 
 
 'Select another shape. 
 ActiveWindow.Select vsoShapes(MAX_SHAPES - 1), visSelect 
 
 'Select the group. 
 ActiveWindow.Select vsoGroup, visSelect 
 
 'Select all but one shape on the page. 
 ActiveWindow.SelectAll 
 ActiveWindow.Select vsoShapes(MAX_SHAPES - 1), visDeselect 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。