lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
Hi,
I am trying to create elbow connectors between two images in the sheet, i prefer it connecting Bottom center of image 1 to Top center of image 2, so that i appears as a tree structure. when i write code it creates between right center of image 1 to left center of image 2, something like it is selecting shortest path, can someone guide me how i can get the desired points to connect.

regards,
lawrence
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Assuming that the active sheet contains your images, and that your images are named "Picture 1" and "Picture 2", try...

Code:
Option Explicit

Sub ConnectTwoImages()


    Dim image1 As Shape
    Dim image2 As Shape
    Dim theConnector As Shape
    
    Set image1 = ActiveSheet.Shapes("Picture 1")
    Set image2 = ActiveSheet.Shapes("Picture 2")
    
    Set theConnector = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
    
    With theConnector.ConnectorFormat
        .BeginConnect ConnectedShape:=image1, ConnectionSite:=1
        .EndConnect ConnectedShape:=image2, ConnectionSite:=1
    End With
    theConnector.RerouteConnections
    
End Sub

Hope this heps!
 
Upvote 0
thank you Domenic for your quick reponse, however it doesnt solve the problem i face,

the Picture 1 is cells("n4") & Picture 2 is in Cell("J6") , i am looking for a hint wherein the elbow connector will connect the bottom center of Picture 1 & top center of picture 2.

the code provided by you above is connecting left center of picture 1 to the right center of picture 2

do you think it can have solution.
 
Upvote 0
Oh yes, you did ask to connect from the bottom center of the first image to the top center of the second image. In that case, try replacing...

Code:
[COLOR=#574123]    With theConnector.ConnectorFormat
[/COLOR]        .BeginConnect ConnectedShape:=image1, ConnectionSite:=1
        .EndConnect ConnectedShape:=image2, ConnectionSite:=1
    End With
 [COLOR=#574123]   theConnector.RerouteConnections[/COLOR]

with

Code:
    With theConnector.ConnectorFormat
        .BeginConnect ConnectedShape:=image1, ConnectionSite:=3
        .EndConnect ConnectedShape:=image2, ConnectionSite:=1
    End With
 
Upvote 0
no Domenic, it still gives the same result, could it something to do with excel 2013. because I use excel 2013.
 
Upvote 0
.jpeg images, inserted using below code

Set p = ActiveSheet.Pictures.Insert(PictureFileName)

where PictureFileName is path.
 
Upvote 0
also i find that,

if i comment block line .BeingConnect then i find that the connector connects to the top of image 2 but throwing out an error, and if i comment block line .EndEonnect then the connector connects the bottom of the image 1
With theConnector.ConnectorFormat
.BeginConnect ConnectedShape:=image1, ConnectionSite:=3
.EndConnect ConnectedShape:=image2, ConnectionSite:=1
End With
 
Upvote 0
thanks Domenic, it works, i had there few lines below went unnoticed, thanks again for your help
theConnector.RerouteConnections
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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