Table of contents
TOC
Collapse the table of content
Expand the table of content

Page.CreateSelection Method (Visio)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Creates various types of Selection objects.

Syntax

expression . CreateSelection( SelType , IterationMode , [Data] )

expression A variable that represents a Page object.

Parameters

NameRequired/OptionalData TypeDescription
SelTypeRequiredVisSelectionTypesThe type of selection. See Remarks for possible values.
IterationModeOptionalVisSelectModeThe selection mode used. See Remarks for possible values.
DataOptionalVariantThe object type that corresponds to the SelType argument. See Remarks for possible values.

Return Value

Selection

Remarks

The CreateSelection method makes it possible to create complex selections programmatically. So instead of having to select all shapes on a page, for example, you can select only those on a given layer, or only those based on a certain master.

Calling the CreateSelection method with SelType equal to visSelTypeByType or visSelTypeByLayer is equivalent to selecting options in the Select byType dialog box (click Select in the Editing group on the Home tab, and then click Select by Type).

The SelType argument should be one of the following values, which are declared in VisSelectionTypes in the Visio type library.

ConstantValueDescription
visSelTypeAll1A selection that initially contains all shapes.
visSelTypeByDataGraphic6A selection that initially contains all shapes that have a given type of data graphic appled.
visSelTypeByLayer3A selection that initially contains all the shapes of a given layer.
visSelTypeByMaster5A selection that initially contains all the instantiated shapes of a given master.
visSelTypeByRole7A selection that initially contains all the shapes of a given role.
visSelTypeByType4A selection that initially contains all the shapes of a given type.
visSelTypeEmpty0A selection that initially contains no shapes.
visSelTypeSingle2A selection that initially contains one shape.

The optional IterationMode argument should be one of the following values, which are declared in VisSelectMode in the Visio type library. The default is visSelModeSkipSuper .

**Constant ****Value ****Description **
visSelModeOnlySub&;H0800Selection only reports subselected shapes.
visSelModeOnlySuper&;H0200Selection only reports superselected shapes.
visSelModeSkipSub&;H0400Selection does not report subselected shapes.
visSelModeSkipSuper&;H0100Selection does not report superselected shapes.

The optional Data argument should be an object that corresponds to the object type specified by SelType. For example, if you want to select all the masters of a certain type, Data should be of type Master . And if you want to select all the shapes on a certain layer, Data should be of type Layer .

When SelType is visSelTypeByRole , Data should be a member of the VisRoleSelectionTypes enumeration.

When the SelType argument is visSelTypeByType , possible Data values should be one of the following values, which are declared in VisTypeSelectionTypes in the Visio type library.

**Constant ****Value ****Description **
visTypeSelBitmap16A shape that is a bitmap.
visTypeSelGroup1A shape that contains other shapes.
visTypeSelGuide4A shape that is a guide.
visTypeSelInk32A shape that is ink.
visTypeSelMetafile8A shape that is a metafile.
visTypeSelOLE64A shape that is linked, embedded, or a control.
visTypeSelShape2A native Visio shape.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to use the CreateSelection method to select all shapes on a particular layer. Before running this macro, create two layers in your drawing, one named "a" and one named "b", and add shapes to both layers.

Public Sub CreateSelection_Layer_Example() 

 Dim vsoLayer As Visio.Layer 
 Dim vsoSelection As Visio.Selection 

 Set vsoLayer = ActivePage.Layers.ItemU("a") 
 Set vsoSelection = ActivePage.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, vsoLayer) 

 Application.ActiveWindow.Selection = vsoSelection 

End Sub

This VBA macro shows how to use the CreateSelection method to select a particular shape on the drawing page. Before running this macro, open the Basic Shapes stencil.

Public Sub CreateSelection_Page_Example() 

 Dim vsoSelection As Visio.Selection 
 Dim vsoShape As Visio.Shape 

 Application.ActiveWindow.Page.Drop Application.Documents("BASIC_U.VSS").Masters.ItemU("Rectangle"), 2, 9 
 Application.ActiveWindow.Page.Drop Application.Documents("BASIC_U.VSS").Masters.ItemU("Rectangle"), 5, 9 
 Application.ActiveWindow.Page.Drop Application.Documents("BASIC_U.VSS").Masters.ItemU("Rectangle"), 2, 7 

 Set vsoShape = ActivePage.Shapes(2) 
 Set vsoSelection = ActivePage.CreateSelection(visSelTypeSingle, visSelModeSkipSuper, vsoShape) 

 Application.ActiveWindow.Selection = vsoSelection 

 Debug.Print vsoShape.Name 

End Sub
© 2017 Microsoft