The below code is part of my process of making a process flow through a userform.
When the "Add" command button is clicked, the object (circle, diamond, rectangle) will be added, and then a connector will connect from top of the new object to the bottom of the previous object. I have included code to check for the presence of the object already and delete it if it already exists (so that the user may click "Add" multiple times, changing the inserted object). However, the connector will not delete. Therefore, if I click Add 10 times, there will only be one object present but 10 connectors, but only one will actually be connected to the objects.
I have tried naming the connector and doing something similar to my method of deleting the objects, but when I do this, it screws up the connector so that it will not connect the two objects.
Can anyone assist me in changing the code so that each time "Add" is clicked, both the object and the connector will be deleted and replaced?
Thank you in advance.
------------------------------------------------------------------------------------
Private Sub Add10_Click()
On Error Resume Next 'Ignore error generated by attempting to delete non-existent object (below)
Dim A As Double
Dim B As Double
Dim C As Double
Dim D As Double
Dim E As Long
A = "400"
B = "475"
C = "12.5"
D = "10.5"
'********************************************************************
'Determines object to be inserted
If Process10 And Not Inspection10 Then
E = msoShapeOval
ElseIf Process10 And Inspection10 = True Then
E = msoShapeRectangle
ElseIf Not Process10 And Inspection10 Then
E = msoShapeDiamond
End If
'********************************************************************
'********************************************************************
'Determines connecting point of previous object
If Process9 And Not Inspection9 Then
H = 5
ElseIf Process9 And Inspection9 = True Then
H = 3
ElseIf Not Process9 And Inspection9 Then
H = 3
End If
'********************************************************************
ActiveSheet.Shapes("P10").Delete ActiveSheet.Shapes.AddShape(E, A, B, C, D).Name = "P10"
'***********************************************************************
'Add connector between above shape and previous shape
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, A + C / 2, B, 0.75, 9).Select
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect ActiveSheet.Shapes("P10"), 1
Selection.ShapeRange.ConnectorFormat.EndConnect ActiveSheet.Shapes("P9"), H
'***********************************************************************************
End Sub
-------------------------------------------------------------------------------------
When the "Add" command button is clicked, the object (circle, diamond, rectangle) will be added, and then a connector will connect from top of the new object to the bottom of the previous object. I have included code to check for the presence of the object already and delete it if it already exists (so that the user may click "Add" multiple times, changing the inserted object). However, the connector will not delete. Therefore, if I click Add 10 times, there will only be one object present but 10 connectors, but only one will actually be connected to the objects.
I have tried naming the connector and doing something similar to my method of deleting the objects, but when I do this, it screws up the connector so that it will not connect the two objects.
Can anyone assist me in changing the code so that each time "Add" is clicked, both the object and the connector will be deleted and replaced?
Thank you in advance.
------------------------------------------------------------------------------------
Private Sub Add10_Click()
On Error Resume Next 'Ignore error generated by attempting to delete non-existent object (below)
Dim A As Double
Dim B As Double
Dim C As Double
Dim D As Double
Dim E As Long
A = "400"
B = "475"
C = "12.5"
D = "10.5"
'********************************************************************
'Determines object to be inserted
If Process10 And Not Inspection10 Then
E = msoShapeOval
ElseIf Process10 And Inspection10 = True Then
E = msoShapeRectangle
ElseIf Not Process10 And Inspection10 Then
E = msoShapeDiamond
End If
'********************************************************************
'********************************************************************
'Determines connecting point of previous object
If Process9 And Not Inspection9 Then
H = 5
ElseIf Process9 And Inspection9 = True Then
H = 3
ElseIf Not Process9 And Inspection9 Then
H = 3
End If
'********************************************************************
ActiveSheet.Shapes("P10").Delete ActiveSheet.Shapes.AddShape(E, A, B, C, D).Name = "P10"
'***********************************************************************
'Add connector between above shape and previous shape
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, A + C / 2, B, 0.75, 9).Select
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect ActiveSheet.Shapes("P10"), 1
Selection.ShapeRange.ConnectorFormat.EndConnect ActiveSheet.Shapes("P9"), H
'***********************************************************************************
End Sub
-------------------------------------------------------------------------------------