Visio) (Window.Selection 屬性

會傳回 Selection 物件以代表目前視窗中選取的項目,或將 CreateSelection 方法所建立的選取範圍指派給 Selection 物件。 讀取/寫入。

語法

運算式選擇

表達 代表 Window 物件的變數。

傳回值

選取項目

註解

Selection 物件與視窗中的選取範圍無關 (這個選取範圍可能會因為使用者動作而變更)。

Selection 物件是一般內容中的圖形組合,您可在其上執行動作。 Selection 物件不只是繪圖視窗中選取的圖形。 您一旦設定或擷取 Selection 物件後,還可以使用 Select 方法來變更該物件所代表的圖形組合。

在使用 CreateSelection 方法建立選取範圍之後,可以接著使用 Selection 屬性在 Microsoft Visio 繪圖視窗中實際顯示新建立的選取範圍。 請參閱下列第二個範例。

範例

下列的 Microsoft Visual Basic for Applications (VBA) 巨集會示範如何使用 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」,然後將圖形新增至這兩個圖層。

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 支援與意見反應