N
Nick Hebb
I'm trying to add some shapes to a canvas, but I'm having trouble
getting the connectors to be positioned properly. The code needs to run
under Word 2000 and 2002, and the object models don't support some of
the newer properties like ConnectorFormat that would make this easier.
Here is some demo code of what I'm trying to do:
Sub AddShapesDemo()
Dim doc As Document
Dim cnvs As Shape
Dim shp1 As Shape
Dim shp2 As Shape
Dim con As Shape
Dim l As Single
Dim t As Single
Dim w As Single
Dim h As Single
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Set doc = ActiveDocument
l = doc.PageSetup.LeftMargin
t = doc.PageSetup.TopMargin
w = Application.InchesToPoints(6)
h = Application.InchesToPoints(9)
Set cnvs = doc.Shapes.AddCanvas(l, t, w, h)
' const 61 = msoShapeFlowchartProcess
Set shp1 = cnvs.CanvasItems.AddShape(61, 20, 20, 96, 25.5)
shp1.TextFrame.TextRange.Text = "Some text"
Set shp2 = cnvs.CanvasItems.AddShape(61, 20, 71.5, 96, 25.5)
shp2.TextFrame.TextRange.Text = "More text"
x1 = shp1.Left + shp1.Width / 2
y1 = shp1.Top + shp1.Height
x2 = shp2.Left + shp2.Width / 2
y2 = shp2.Top
' const 2 = msoConnectorElbow
Set con = cnvs.CanvasItems.AddConnector(2, x1, y1, x2, y2)
Set shp1 = Nothing
Set shp2 = Nothing
Set con = Nothing
Set cnvs = Nothing
Set doc = Nothing
End Sub
The problem is, after the code runs, the connector is positioned
horizontally in the middle of the first shape. Anyone know what the
problem with the code is and how I can correct it?
Thanks,
Nick Hebb
getting the connectors to be positioned properly. The code needs to run
under Word 2000 and 2002, and the object models don't support some of
the newer properties like ConnectorFormat that would make this easier.
Here is some demo code of what I'm trying to do:
Sub AddShapesDemo()
Dim doc As Document
Dim cnvs As Shape
Dim shp1 As Shape
Dim shp2 As Shape
Dim con As Shape
Dim l As Single
Dim t As Single
Dim w As Single
Dim h As Single
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Set doc = ActiveDocument
l = doc.PageSetup.LeftMargin
t = doc.PageSetup.TopMargin
w = Application.InchesToPoints(6)
h = Application.InchesToPoints(9)
Set cnvs = doc.Shapes.AddCanvas(l, t, w, h)
' const 61 = msoShapeFlowchartProcess
Set shp1 = cnvs.CanvasItems.AddShape(61, 20, 20, 96, 25.5)
shp1.TextFrame.TextRange.Text = "Some text"
Set shp2 = cnvs.CanvasItems.AddShape(61, 20, 71.5, 96, 25.5)
shp2.TextFrame.TextRange.Text = "More text"
x1 = shp1.Left + shp1.Width / 2
y1 = shp1.Top + shp1.Height
x2 = shp2.Left + shp2.Width / 2
y2 = shp2.Top
' const 2 = msoConnectorElbow
Set con = cnvs.CanvasItems.AddConnector(2, x1, y1, x2, y2)
Set shp1 = Nothing
Set shp2 = Nothing
Set con = Nothing
Set cnvs = Nothing
Set doc = Nothing
End Sub
The problem is, after the code runs, the connector is positioned
horizontally in the middle of the first shape. Anyone know what the
problem with the code is and how I can correct it?
Thanks,
Nick Hebb