第 19 章 VISIO ソリューションでの接続のオートメーション化
次の Microsoft Visual Basic for Applications (VBA) プログラムでは、このプロシージャに引数として渡された配列に含まれるデータに基づいて、Visio® の図面ページ上に簡単なフローチャートを描画します。渡される配列は 2 次元で、最初の要素にはマスタシェイプの名前、2 番目の要素にはシェイプの文字が格納されています。プロシージャは、フローチャートを作成する前に配列データを読み込み、Visual Basicエディタのイミディエイト ウィンドウにその内容を表示します。
CreateFlowchart によって作成されたフローチャート
Public Sub CreateFlowchart(arrFlowChart () As String) |
|
On Error GoTo eHandler
'Initialize X, Y location that we will pass to the Drop method
dblXLocation = 4.25
dblYLocation = 10.5
'Print array to Immediate window
For iCount = LBound(arrFlowData) To UBound(arrFlowData)
Debug.Print arrFlowData(iCount, 0) & " "; arrFlowData(iCount, 1)
Next
'Open Flowchart stencil
Set vStencil = Application.Documents.OpenEx _
("基本フローチャート.vss", visOpenDocked)
'Add a shape to the drawing for each item in the array
For iCount = LBound(arrFlowData) To UBound(arrFlowData)
'Get the Master based on MasterName in the data array
Set vFlowChartMaster = vStencil.Masters(arrFlowData(iCount, 0))
'Add the shape to the page
Set vNextShape = ActivePage.Drop(vFlowChartMaster, dblXLocation, _
dblYLocation)
'Set dropped shape text
vNextShape.Text = arrFlowData(iCount, 1)
'Connect to Previous shape dropped, if necessary
If Not vPrevShape Is Nothing Then
'Get Connector Master if necessary
If vConnectorMaster Is Nothing Then
Set vConnectorMaster = vStencil.Masters("動的コネクタ")
End If
'Add Connector to the page (doesn't matter where for this example)
Set vConnector = ActivePage.Drop(vConnectorMaster, 0, 0)
'Connect Begin Point
Set bCell = vConnector.Cells("BeginX")
bCell.GlueTo vPrevShape.Cells("AlignBottom")
'Connect End Point
Set eCell = vConnector.Cells("EndX")
eCell.GlueTo vNextShape.Cells("AlignTop")
vConnector.SendToBack
End If
Set vPrevShape = vNextShape
Set vNextShape = Nothing
'Set Y location for next shape
dblYLocation = dblYLocation - 1.5
Next
Exit Sub
eHandler:
Debug.Print Error
End Sub