vba - Excel 2013 Add a Connector Between Arbitrary Points on Two Different Groups -


i'm working in excel 2013 (programmatically) add straight line connector between lower right hand corner of rectangle part of grouped shape endpoint of grouped series of line segments. stands, can't seem manually on excel worksheet contains these shapes.

problems include:

  1. only midpoints on desired rectangle accept connector.
  2. the grouped series of line segments don't show "connection point" terminating end of straight line connector.

here's graphic of i'm trying do:

[i don't have 10 "reputation points" can't seem post picture of i'm trying do. not helpful feature! how reputation points in game?]

i've been able create , name 2 groups , thought cinch work them add connector, has not been case.

here's code i've been working with:

sub create_new_profile()     dim firstrect shape     dim firstline shape     set mydocument = worksheets(1)     set s = mydocument.shapes '    set firstrect = s.range("shpnewgarage") '    set firstline = s.range("shpprofile")     dim shp shape '    each shp in mydocument.shapes     each shp in s         if shp.name = "shpnewgarage"             set firstrect = shp     else     end if     next shp '    each shp in mydocument.shapes     each shp in s         if shp.name = "shpprofile"             set firstline = shp     else     end if     next shp     firstrect.select 'this works     firstline.select 'this works '    set firstrect = s.addshape(msoshaperectangle, 100, 50, 200, 100) '    set firstline = s.addshape(msoshaperectangle, 300, 300, 200, 100) '    set firstrect = activesheet.shapes.range("shpnewgarage") '    set firstline = activesheet.shapes.range("shpprofile")     dim c shape     set c = s.addconnector(msoconnectorstraight, 0, 0, 100, 100) '    on error resume next     c.connectorformat       **.beginconnect connectedshape:=firstrect, connectionsite:=1**       .endconnect connectedshape:=firstline, connectionsite:=1 '     .beginconnect connectedshape:="shpnewgarage", connectionsite:=1 '     .endconnect connectedshape:="shpprofile", connectionsite:=1 '     .beginconnect connectedshape:=activesheet.shapes.range("shpnewgarage"), connectionsite:=1 '     .endconnect connectedshape:=activesheet.shapes.range("shpprofile"), connectionsite:=1      c.rerouteconnections     end end sub 

this particular version of code ends runtime error on line following line:

with c.connectorformat

here's error message:

[i don't have 10 "reputation points" can't seem post picture of error message i'm getting. again, how reputation points?]

any direction @ me accomplish task programmatically appreciated.

thanks explaining can post images. should help.

here figures i'm working with:

new garage, existing driveway profile , new profile (red.)

the rectangle group (firstrect, "shpnewgarage") represents new garage plan build between existing 1 , street. profile group (firstline, "shpprofile") represents profile (side view/elevation) of existing driveway (the light blue line.) idea attach new profile (red line) lower right corner of new garage @ 1 end , right end of existing profile (curb) move new garage up, down, right , left, connector representing new profile remain attached these points show graphically angle (grade) , length of new driveway.

here's error message receive when run code:

vba error message.

this looks quite hill climb, having problems adding connector desired points manually.

thanks have read/responded issue. stackoverflow has been great resource me in past, , first time i've ever had post own specific problem.

you explained well, , images uploaded helped

what code doing seems correct, error complaining 1 of parameters, , 2nd one:

.beginconnect connectedshape:=firstrect, connectionsite:=1

connectionsite: "a connection site on shape specified connectedshape. must integer between 1 , integer returned connectionsitecount property of specified shape"

i think firstrect has problem first node: when generate rectangle doesn't have connection points in corners, , i'm not sure initial available nodes

a rectangle specific class of shape must first converted (generic) shape class: "you must apply addnodes method freeformbuilder object @ least once before use converttoshape method", in order add connection points (nodes) corner

another issue might caused groups. i'm not sure if grouped objects, grouping may not allow direct access connection points

as exercise, able draw lines between 2 rectangles way intended, lines not connected shapes, if move 1 rectangle lines not move it. here code:

option explicit  sub create_new_profile()      dim ws worksheet      dim shp1 shape     dim shp2 shape      dim line1 shape     dim line2 shape      set ws = sheet1      ws.shapes          'addshape:        left=10, top=10, width=50, height=30         set shp1 = .addshape(msoshaperectangle, 10, 10, 50, 30)         set shp2 = .addshape(msoshaperectangle, 70, 50, 50, 30)          'addconnector:          beginx=60, beginy=10, endx=120, endy=50         set line1 = .addconnector(msoconnectorstraight, 60, 10, 120, 50)         set line2 = .addconnector(msoconnectorstraight, 60, 40, 120, 80)     end      line1.line.forecolor.rgb = rgb(255, 0, 0)   'color red     line2.line.forecolor.rgb = rgb(255, 0, 0)  end sub 

and end result:

connected shapes

.

if need lines linked rectangles, you'll have convert rectangles shapes, add corner connection points or nodes (msoeditingcorner), add connector lines 1 corner node of first rectangle other corner node of second rectangle

one of ways (manually) convert shape, , record actions see generated vba code , objects used, right-clicking shape , selecting "edit points":

enter image description here

hope helps bit


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -