Shapeを使う - Shapeをコネクタでつなぐには
 図形同士を線でつなぐとき、Connectorで線を描画し、その始点と終点を
接続対象となるShapeに接続します。このとき、Connectorと図形の接続位置
を決めるのは計算によるか、または簡易法としてConnectorFormatオブジェク
トとそのメンバであるBeginConnect,EndConnectメソッドを用いてから、
コネクタをRerouteConnectionsメソッドによって再接続すると便利です。

(サンプル - 二つの円を描画し、コネクタで接続します)

Private Sub CommandButton1_Click()

    Dim Shape1 As Shape, Shape2 As Shape, ShapeCon As Shape

    Set Shape1 = ActiveSheet.Shapes.AddShape _
                       (msoShapeOval, 100, 100, 50, 50)
    Set Shape2 = ActiveSheet.Shapes.AddShape _
                       (msoShapeOval, 300, 100, 50, 50)

    'コネクタ描画 ※位置は仮決め
    Set ShapeCon = ActiveSheet.Shapes.AddConnector _
                       (msoConnectorStraight, 1, 1, 1, 1)

    'コネクタを再接続
    With ShapeCon
        .ConnectorFormat.BeginConnect Shape1, 1
        .ConnectorFormat.EndConnect Shape2, 1
        .RerouteConnections
    End With

End Sub

※上記サンプルにおいてコネクタの位置を仮決めにしてあるのは、
RerouteConnectionsメソッドによって再接続すると、最初に指定
したコネクタの位置と大きさは自動的に調整されるためです。

Excel97,2000



戻る


Excel Word Access VBA! モーグ