第 19 章 VISIO ソリューションでの接続のオートメーション化
次の ShowPageConnections マクロは、アクティブな Visio® 図面の最初のページにある Connect オブジェクトによって繰り返されます。ShowPageConnections は、それぞれの Connect オブジェクトを対象に、接続された図形 ( FromSheet と ToSheet ) と接続された図形の一部 (FromPart と ToPart) を取得します。次に、Visio のタイプ ライブラリの定数を使用して、FromPart と ToPart の値を実際の値と比較し、対応する文字列を、接続に関する他のデータと共にユーザーフォームのリスト ボックスに表示します。
Sub ShowPageConnections ()
Dim pagsObj As Visio.Pages 'Page collection of document
Dim pagObj As Visio.Page 'Page to work on
Dim fromObj As Visio.Shape 'Object From connection connects to
Dim toObj As Visio.Shape 'Object To connection connects to
Dim consObj As Visio.Connects 'Connects collection
Dim conObj As Visio.Connect 'Connect object from collection
Dim fromData As Integer 'Type of From connection
Dim fromStr As String 'String to hold description of From connection
Dim toData As Integer 'Type of To connection
Dim toStr As String 'String to hold description of To connection
'Get the Pages collection for the document
'Note the use of ThisDocument to refer to the current document
Set pagsObj = ThisDocument.Pages
'Get a reference to the first page of the collection
Set pagObj = pagsObj(1)
'Get the Connects collection for the page
Set consObj = pagObj.Connects
'Make sure the list box is empty.
UserForm1.ListBox1.Clear
'Loop through the Connects collection
For Each conObj In consObj
'Get the current Connect object from the collection
Set conObj = consObj(curConnIndx)
'Get the From information
Set fromObj = conObj.FromSheet
fromData = conObj.FromPart
'Get the To information
Set toObj = conObj.ToSheet
toData = conObj.ToPart
'Use fromData to determine type of connection
If fromData = visConnectError Then
fromStr = "error"
ElseIf fromData = visNone Then
fromStr = "none"
'Test fromData for visRightEdge,visBottomEdge,visMiddleEdge,
'visTopEdge,visLeftEdge,visCenterEdge, visBeginX, visBeginY, visBegin, visEndX,
'visEndY,visEnd
ElseIf fromData >= visControlPoint Then
fromStr = "controlPt_" & CStr(fromData - visControlPoint + 1)
Else
fromStr = "???"
End If
'Use toData to determine the type of shape the connector is connected to
If toData = visConnectError Then
toStr = "error"
ElseIf toData = visNone Then
toStr = "none"
ElseIf toData = visGuideX Then
toStr = "guideX"
ElseIf toData = visGuideY Then
toStr = "guideY"
ElseIf toData >= visConnectionPoint Then
toStr = "connectPt_" & CStr(toData - visConnectionPoint + 1)
Else
toStr = "???"
End If
'Add the information to the list box
UserForm1.ListBox1.AddItem "from " & fromObj.Name & " " & fromStr & " to " & _
toObj.Name & " " & toStr
Next
UserForm1.Show
End Sub