Window.Selection プロパティ (Visio)

現在ウィンドウで選択されている項目を表す Selection オブジェクトを返すか、または CreateSelection メソッドによって作成された選択項目を Selection オブジェクトに割り当てます。 値の取得と設定が可能です。

構文

選択

Window オブジェクトを表す変数。

戻り値

Selection

注釈

Selection オブジェクトはウィンドウの選択から独立しており、ユーザー アクションの結果、後で変更されることがあります。

Selection オブジェクトは、アクションを実行できる共通コンテキスト内の図形のセットです。 Selection オブジェクトは、図面ウィンドウで選択された図形に類似しています。 Selection オブジェクトを設定または取得した後に、Select メソッドを使用してオブジェクトが表す図形のセットを変更できます。

CreateSelection メソッドを使用して選択項目を作成した後に、Selection プロパティを使って、新規に作成された選択項目を Microsoft Visio 図面ウィンドウに実際に表示できます。 詳細については 2 番目の例を参照してください。

この VBA (Microsoft Visual Basic for Applications) マクロは、Selection プロパティを使用して、ウィンドウ内で選択されているすべての図形を取得する方法を示します。

Public Sub Selection_Example() 
 
 Const MAX_SHAPES = 6 
 Dim vsoShapes(1 To MAX_SHAPES) As Visio.Shape 
 Dim vsoSelection As Visio.Selection 
 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 
 
 'Deselect all the shapes in the active window. 
 ActiveWindow.DeselectAll 
 
 'Select all the shapes in the active window. 
 ActiveWindow.SelectAll 
 
 'Get the selected shapes and assign them to a Selection object. 
 Set vsoSelection = ActiveWindow.Selection 
 
End Sub

この VBA マクロは、CreateSelection メソッドを使用して、特定のレイヤーのすべての図形を選択する方法を示します。 次に 、Selection プロパティを使用して、Visio 図面ウィンドウに選択範囲を表示します。

このマクロを実行する前に、"a" という名前のレイヤーと "b" という名前の 2 つのレイヤーを図面に作成し、両方のレイヤーに図形を追加します。

Public Sub Selection_Example_2() 
 
 Dim vsoLayer As 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

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。