Connecting shapes between connections points by VBA ????

keldsor

Board Regular
Joined
Jun 9, 2017
Messages
52
I have some named shapes on the active sheet - let's say then names are "28", "28+31" and "31".

They have got their names from some LONG PId's in my Access DB - never mind that !

"28" and "31" are in fact som ractangles and between them - a little lower on the sheet - is a triangle - this construction represents 2 persons (the rectangles) and the triangle shows they are merried !

I now want to connect a msoConnectorElbow with an msoArrowheadOpen from each person starting from the middle of the lower side of each rectangle to each side of the triangle.

I use this code taken from a recording of a macro, edited a little and copied to this sub :

HTML:
Public Sub setArrowsOn(PId1 As Long, PId2 As Long)
    ActiveSheet.Shapes(Trim(Str(PId1))).AddConnector(msoConnectorElbow, 100, 100, 100, 100).Select
    Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadOpen
    Selection.ShapeRange.ConnectorFormat.BeginConnect ActiveSheet.Shapes(Trim(Str(PId1))), 3
    Selection.ShapeRange.ConnectorFormat.EndConnect ActiveSheet.Shapes(PId1 & "+" & PId2), 2
End Sub

I get run time error 438 Obj doesn't support this property or method in the marked line !!!!!!!!!!!!!!!!!!!!

What do I do wrong here ?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try...

Code:
[FONT=Courier New][COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Sub[/COLOR] setArrowsOn(PId1 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], PId2 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR])
    [COLOR=darkblue]Dim[/COLOR] Conn [COLOR=darkblue]As[/COLOR] Shape
    [COLOR=darkblue]Dim[/COLOR] Wks [COLOR=darkblue]As[/COLOR] Worksheet
    
    [COLOR=darkblue]Set[/COLOR] Wks = ActiveSheet
    
    [COLOR=darkblue]Set[/COLOR] Conn = Wks.Shapes.AddConnector(msoConnectorElbow, 100, 100, 100, 100)
    [COLOR=darkblue]With[/COLOR] Conn
        .Line.EndArrowheadStyle = msoArrowheadOpen
        .ConnectorFormat.BeginConnect Wks.Shapes(Trim(Str(PId1))), 3
        .ConnectorFormat.EndConnect Wks.Shapes(PId1 & "+" & PId2), 2
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
    [COLOR=darkblue]Set[/COLOR] Conn = Wks.Shapes.AddConnector(msoConnectorElbow, 100, 100, 100, 100)
    [COLOR=darkblue]With[/COLOR] Conn
        .Line.EndArrowheadStyle = msoArrowheadOpen
        .ConnectorFormat.BeginConnect Wks.Shapes(Trim(Str(PId2))), 3
        .ConnectorFormat.EndConnect Wks.Shapes(PId1 & "+" & PId2), 6
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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