Shape.ConnectedShapes 方法 (Visio)
會傳回一個陣列,內含已連接至此圖形之各圖形的識別碼 (ID)。
語法
expression。 ConnectedShapes
( _Flags_
, _CategoryFilter_
)
表達 代表 Shape 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
Flags | 必要 | VisConnectedShapesFlags | 依據連接器的方向性,篩選所傳回的圖形 ID 陣列。 如需可能的值,請參閱<備註>。 |
CategoryFilter | 必要 | 字串 | 將圖形的 ID 限制為需符合指定的類別,藉以篩選所傳回的圖形 ID 陣列。 |
傳回值
Long ()
註解
Flags 的值必須是下列其中一個 VisConnectedShapesFlags 常數。
常數 | 值 | 描述 |
---|---|---|
visConnectedShapesAllNodes | 0 | 會傳回兼具向內和向外連接關聯之各圖形的 ID。 |
visConnectedShapesIncomingNodes | 1 | 會傳回具有向內連接關聯之各圖形的 ID。 |
visConnectedShapesOutgoingNodes | 2 | 會傳回具有向外連接關聯之各圖形的 ID。 |
類別是由使用者定義的字串,可用來將圖形分類進而限制容器內的成員資格。 您可以在圖形的 ShapeSheet 中從 User.msvShapeCategories 儲存格來定義類別。 若要為圖案定義多個類別,請以分號分隔各類別。
如果來源物件是 1D 圖形或主圖形的一部分, ConnectedShapes 方法會 傳回不正確來源錯誤。
如果所有連接的圖形都不符合條件,ConnectedShapes 方法將傳回一個空陣列。
範例
下列 Visual Basic for Applications (VBA) 宏會示範如何使用 ConnectedShapes 方法,從選取的圖形尋找連出連線另一端的所有圖形名稱。
範例程式碼提供者:複寫
Public Sub ConnectedShapes_Outgoing_Example()
' Get the shapes that are connected to the selected shape
' by outgoing connectors.
Dim vsoShape As Visio.Shape
Dim lngShapeIDs() As Long
Dim intCount As Integer
If ActiveWindow.Selection.Count = 0 Then
MsgBox ("Please select a shape that has connections")
Exit Sub
Else
Set vsoShape = ActiveWindow.Selection(1)
End If
lngShapeIDs = vsoShape.ConnectedShapes _
(visConnectedShapesOutgoingNodes, "")
Debug.Print "Shapes at the end of outgoing connectors:"
For intCount = 0 To UBound(lngShapeIDs)
Debug.Print ActivePage.Shapes(lngShapeIDs(intCount)).Name
Next
End Sub
下列 VBA 宏示範如何使用 ConnectedShapes 方法來尋找所選圖形之連入連線另一端的所有圖形名稱。
範例程式碼提供者:複寫
Public Sub ConnectedShapes_Incoming_Example()
' Get the shapes that are at the other end of
' incoming connections to a selected shape
Dim vsoShape As Visio.Shape
Dim lngShapeIDs() As Long
Dim intCount As Integer
If ActiveWindow.Selection.Count = 0 Then
MsgBox ("Please select a shape that has connections.")
Exit Sub
Else
Set vsoShape = ActiveWindow.Selection(1)
End If
lngShapeIDs = vsoShape.ConnectedShapes _
(visConnectedShapesIncomingNodes, "")
Debug.Print "Shapes that are at the other end of incoming connections:"
For intCount = 0 To UBound(lngShapeIDs)
Debug.Print ActivePage.Shapes(lngShapeIDs(intCount)).Name
Next
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應