Question

Locked

Word 2003 VBA - program access to position of Shapes within a Canvas ?

By Aeggie ·
Hello,

In word 2003, I am trying to work programmably on shapes placed within a canvas.

Creating them in the right position in the canvas is ok:
With shpCanvasShapes
Set newshape = .AddShape(msoShapeRectangle, 50, 50, 100, 200)
MsgBox newshape.Name
End With

However, I cant figure how to programmably test or modify their position relatively to the canvas they are placed in...

With ActiveDocument.Shapes("canvas 2").CanvasItems
Set newshape1 = .AddShape(msoShapeRectangle, 50, 50, 100, 200)
MsgBox newshape1.Name & vbTab & newshape1.Left
Set newshape2 = .AddShape(msoShapeRectangle, 100, 50, 100, 200)
MsgBox newshape2.Name & vbTab & newshape2.Left
End With

The "left" property always give me the left position of the canvas (same value for both new shapes) not of the shape by itself !

Does someone know the function / property / trick for reading and modifying the individual position of each CanvasShape / CanvasItem ?

Thanks a lot in advance
Aeggie

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

.canvasitems. ?

by TobiF In reply to Word 2003 VBA - program a ...

Maybe you need to talk about canvasitems, rather than shapes (where canvas is yet another "shape") Not sure, though.
I found this example in vba help:


Sub AddInlineCanvas()
Dim docNew As Document
Dim shpCanvas As Shape

Set docNew = Documents.Add

'Add a drawing canvas to the new document
Set shpCanvas = docNew.Shapes.AddCanvas( _
Left:=150, Top:=150, Width:=70, Height:=70)
shpCanvas.WrapFormat.Type = wdWrapInline

'Add shapes to drawing canvas
With shpCanvas.CanvasItems
.AddShape msoShapeHeart, Left:=10, _
Top:=10, Width:=50, Height:=60
.AddLine BeginX:=0, BeginY:=0, _
EndX:=70, EndY:=70
End With
With shpCanvas
.CanvasItems(1).Fill.ForeColor _
.RGB = RGB(Red:=255, Green:=0, Blue:=0)
.CanvasItems(2).Line _
.EndArrowheadStyle = msoArrowheadTriangle
End With
End Sub

Collapse -

well, still looking for reading internal position :-)

by Aeggie In reply to .canvasitems. ?

Thank you for your quick answer

Well, i didnt find this help page at first, and youre right that 'canvasitems' is to be used.
however, while the shape (heart) is duly created with this code,
the value returned for position of this shape is still the one of the canvas :-(
MsgBox shpCanvas.CanvasItems(3).Left

i also found a "incrementLeft" method, member of Shape, which enable to move the shape within the canvas,
but nothing yet to read the position of a previously existing shape

(my goal is to be able to automatically place several existing bax, a bit like does the "align" or "distribute")

Aeggie

Collapse -

Can you go around?

by TobiF In reply to well, still looking for r ...

Have you tried to convert the canvasitems to separate shapes before playing with them?

I just noted such a possible action, but haven't gone deeper.

I don't know if you afterwards can convert these items back into one canvas...

Collapse -

Damn

by santeewelding In reply to Can you go around?

Talk about abstruse.

Back to Software Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums