Connecting Two Objects - Please Help

jbrouse

Active Member
Joined
Apr 28, 2005
Messages
329
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


-------------------------------------------------------------------------------------
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top