會傳回一個陣列,內含已連接至此圖形之各圖形的識別碼 (ID)。
語法
expression。
ConnectedShapes( _Flags_ , _CategoryFilter_ )
expression 一個用於表示 Shape 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Flags | 必要 | VisConnectedShapesFlags | 依據連接器的方向性,篩選所傳回的圖形 ID 陣列。 如需可能的值,請參閱<備註>。 |
| 分類過濾器 | 必要 | 字串 | 將圖形的 ID 限制為需符合指定的類別,藉以篩選所傳回的圖形 ID 陣列。 |
傳回值
長 ()
註解
Flags 的值必須是下列其中一個 VisConnectedShapesFlags 常數。
| 常數 | 值 | 描述 |
|---|---|---|
| visConnectedShapesAllNodes | 0 | 會傳回兼具向內和向外連接關聯之各圖形的 ID。 |
| visConnectedShapesIncomingNodes | 1 | 會傳回具有向內連接關聯之各圖形的 ID。 |
| visConnectedShapesOutgoingNodes | 2 | 會傳回具有向外連接關聯之各圖形的 ID。 |
類別是由使用者定義的字串,可用來將圖形分類進而限制容器內的成員資格。 您可以在圖形的 ShapeSheet 中從 User.msvShapeCategories 儲存格來定義類別。 若要為圖案定義多個類別,請以分號分隔各類別。
若來源物件是一維形狀或主圖的一部分, ConnectedShapes 方法會回傳「無效原始碼」錯誤。
如果所有連接的圖形都不符合條件,ConnectedShapes 方法將傳回一個空陣列。
範例
以下的 Visual Basic for Applications (VBA) 巨集 展示了如何使用 ConnectedShapes 方法,找出從所選形狀輸出連接另一端的所有形狀名稱。
範例程式碼由:
Fred Diggs 提供
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 方法,找出所有來自輸入連接另一端所有形狀的名稱。
範例程式碼由:
Fred Diggs 提供
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 支援與意見反應。