Vincent Verheul was telling us:
Vincent Verheul nous racontait que :
Hello Jean-Guy,
Thanks for your response. I already use code that you illustrated
(except for the grouping) and I am aware of the fact the connector
uses an absolute beginning and a relative (offset) ending in its
specification.
The resulting image looks neat, but there is still a problem: you can
not drag a rectangle to another position without losing the
connectors. You can see that the connectors are not *connected* to
the rectangles in Word when you select a connector: the endings are
*Green* where I want them to be *Red*. A Red connector junction
indicates that it is connected to the shape (an not just positioned
next to it).
An important effect of a connector being *connected* (I use an Elbow
connector) is that it is shaped neatly between the Rectangles without
having a portion of it running in parallel to a side of the rectangle
for instance.
I think there should somehow be a link between the connector and the
Rectangle shapes that it is to connect to.
Any ideas?
Sorry, no.
If you add a connector and record it you get this:
'_______________________________________
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 6/16/2006 by Jean-Guy Marcil
'
ActiveDocument.Shapes.AddConnector(msoConnectorStraight, 270#, 189.05, _
81#, 8.95).Select
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect
ActiveDocument.Shapes( _
"Rectangle 126"), 4
Selection.ShapeRange.ConnectorFormat.EndConnect ActiveDocument.Shapes( _
"Rectangle 127"), 2
End Sub
'_______________________________________
Now, delete the connector you just added and run the exact same recorded
code again, you get an error.
I managed to get:
'_______________________________________
Dim shpCanvas As Shape
Dim shpConnect As Shape
Dim shpBox1 As Shape
Dim shpBox2 As Shape
Set shpCanvas = ActiveDocument.Shapes.AddCanvas( _
Top:=75, Left:=100, Width:=200, Height:=200)
shpCanvas.Name = "Canvas"
With shpCanvas.CanvasItems
Set shpBox1 = .AddShape(Type:=msoShapeRectangle, Top:=25, _
Left:=25, Width:=50, Height:=30)
shpBox1.Name = "Rec1"
Set shpBox2 = .AddShape(Type:=msoShapeRectangle, Top:=25, _
Left:=100, Width:=50, Height:=30)
shpBox1.Name = "Rec2"
Set shpConnect = .AddConnector(msoConnectorStraight, 75, 40, 25, 0)
End With
shpConnect.Select
Selection.ShapeRange.ConnectorFormat.BeginConnect shpBox1, 3
Selection.ShapeRange.ConnectorFormat.EndConnect shpBox2, 1
'_______________________________________
But I get an error on the last two lines because (according to Word and even
if I used the .AddConnector method) the selected object is not a connector.
I think these properties work in Excel or PowerPoint but were poorly
implemented in Word.
Nothing about them in the online help by the way.
For example, this works in Excel:
'_______________________________________
Dim shpConnect As Shape
Dim shpBox1 As Shape
Dim shpBox2 As Shape
With Worksheets(1).Shapes
Set shpBox1 = .AddShape(Type:=msoShapeRectangle, Top:=25, _
Left:=25, Width:=50, Height:=30)
shpBox1.Name = "Rec1"
Set shpBox2 = .AddShape(Type:=msoShapeRectangle, Top:=25, _
Left:=100, Width:=50, Height:=30)
shpBox1.Name = "Rec2"
Set shpConnect = .AddConnector(msoConnectorStraight, 75, 40, 25, 0)
End With
With shpConnect
.ConnectorFormat.BeginConnect shpBox1, 3
.ConnectorFormat.EndConnect shpBox2, 1
End With
'_______________________________________
It is a shame because there are may properties to the ConnectorFormat you
would have been able to use. (Like accessing the parent shapes, the
connected sites, etc.)
May be you could create the whole drawing in Excel, then import it in a Word
canvas (In Word you need a canvas for the connector stuff to work, not in
Excel)...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org