モジュールレベル変数
Option Explicit
Dim SC As ShapeClass
Dim start_shape As Shape
Dim StartPosition As Long
Dim end_shape As Shape
Dim EndPosition As Long
ブロック追加ボタンクリック
Private Sub AddChartButton_Click()
SC.myShape.Delete
On Error Resume Next
Dim PositionRelationIndex As Long
PositionRelationIndex = SC.GetPositionRelation(start_shape, end_shape)
Dim myLeft As Long
Dim myTop As Long
Select Case PositionRelationIndex
Case 1, 3
myLeft = start_shape.Left
myTop = (start_shape.Top + end_shape.Top) / 2
Case 2, 4
myLeft = (start_shape.Left + end_shape.Left) / 2
myTop = start_shape.Top
Case 5, 8
myLeft = end_shape.Left
myTop = start_shape.Top
Case 6, 7
myLeft = start_shape.Left
myTop = end_shape.Top
End Select
Dim myHeight As Double
myHeight = end_shape.Height
Dim myWidth As Double
myWidth = start_shape.Width
Set SC.myShape = ActiveSheet.Shapes.AddShape(msoShapeFlowchartProcess, myLeft, myTop, myWidth, myHeight)
SC.myShape.TextFrame2.TextRange.Characters.Text = AddChartTextBox.Value
SC.myShape.OnAction = "SelectShape"
SC.SetFormat
Dim AddShape(1 To 3) As Shape
Set AddShape(1) = start_shape
Set AddShape(2) = SC.myShape
Set AddShape(3) = end_shape
Dim i As Long
For i = 1 To 2
ConnectShape AddShape(i), AddShape(i + 1)
Next
Set ECoC = New EditConnectorClass
Call ECoC.UpdateConnectorList
If EditChartFlag = True Then
Set EChC = New EditChartClass
With EditChartForm.ListBox1
.Clear
.List = EChC.ShapeList
Call EChC.UpdateOrder
End With
End If
End Sub
追加ブロック用テキスト
Private Sub AddChartTextBox_Change()
Call ECoC.ControlAddChartButton
End Sub
リストボックスの項目選択
Private Sub ListBox2_Change()
On Error Resume Next
Dim ConnectorName As String
ConnectorName = ListBox2.List(ListBox2.ListIndex)
If Err.Number = 381 Then
Exit Sub
End If
Set SC = New ShapeClass
Set SC.myShape = ActiveSheet.Shapes(ConnectorName)
SC.myShape.Select
Set ECoC = New EditConnectorClass
With ECoC
.ConnectorName = ConnectorName
Set start_shape = .start_shape
StartPosition = .StartPosition
Set end_shape = .end_shape
EndPosition = .EndPosition
Call .ControlAddChartButton
End With
End Sub
始端用スピンボタン
Private Sub StartSpinButton_Change()
If Not start_shape Is Nothing Then
SC.myShape.ConnectorFormat.BeginConnect start_shape, StartPosition
End If
Select Case StartSpinButton.Value
Case StartSpinButton.Max, StartSpinButton.Min
StartSpinButton.Value = StartSpinButton.Max / 2
End Select
End Sub
Private Sub StartSpinButton_SpinUp()
StartPosition = StartPosition Mod 4 + 1
End Sub
Private Sub StartSpinButton_SpinDown()
Select Case StartPosition
Case 1
StartPosition = 4
Case Else
StartPosition = StartPosition - 1
End Select
End Sub
終端用スピンボタン
Private Sub EndSpinButton_Change()
If Not end_shape Is Nothing Then
SC.myShape.ConnectorFormat.EndConnect end_shape, EndPosition
End If
Select Case EndSpinButton.Value
Case EndSpinButton.Max, EndSpinButton.Min
EndSpinButton.Value = EndSpinButton.Max / 2
End Select
End Sub
Private Sub EndSpinButton_SpinUp()
EndPosition = EndPosition Mod 4 + 1
End Sub
Private Sub EndSpinButton_SpinDown()
Select Case EndPosition
Case 1
EndPosition = 4
Case Else
EndPosition = EndPosition - 1
End Select
End Sub
ユーザーフォームの初期化
Private Sub UserForm_Initialize()
StartSpinButton.Value = StartSpinButton.Max / 2
EndSpinButton.Value = EndSpinButton.Max / 2
End Sub
ユーザーフォームを閉じるときのフラグ変更
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VBA.VbQueryClose.vbFormControlMenu Then
EditConnectorFlag = False
End If
End Sub