vba to select multiple shapes on a drawing canvas

M

Mona-ABE

I need to select multiple and specific shapes on a drawing canvas after they
have been drawn automatically with programming (using vba).

I have all the objects below defined in my code:

Dim myDoc As Document
Set myDoc = Application.ActiveDocument

Dim myCanvas As Shape

Set myCanvas = myDoc.Shapes(strCanvas) 'this is a variable supplied by
the

'argument in the procedure call
Dim shpCanvasShapes As CanvasShapes
Set shpCanvasShapes = myCanvas.CanvasItems

Dim myShape As Shape
Set myShape = shpCanvasShapes.AddTextbox (or AddAnyOtherShape...........)

After I've done this several times, I need to go back and "group" 5 shapes
that have been drawn on the canvas programmatically. Please point me in the
right direction to do this in Microsoft Word 2003.
 
O

old man

Hi,

A canvas is just another shape in word. The objects are child objects in the
canvas - lets say the canvas is the first shape in the page then this will
select the first two drawing objects on the canvas (shapes that are not
inline shapes have names automatically assigned to them and after they are
created you can read the name and then reassign a meaningful name through
vba.)

ActiveDocument.Shapes(1).CanvasItems.Range(Array(1, 2)).Select

Set range1 = Selection.Range

This assumes the first shape in the document is a canvas and has at least
two ojects in it.
old man
 
M

Mona-ABE

You saved my life!

With your excellent explanation, I put this together and it's working
perfectly!

intSelTxtBx = shpCanvasShapes.Count

ActiveDocument.Shapes(strCanvas).CanvasItems.Range(Array(intSelTxtBx -
4, intSelTxtBx - 3, intSelTxtBx - 2, intSelTxtBx - 1, intSelTxtBx)).Group

I'm so thankful for this forum, and for contributors like you!
 
O

old man

Hi,

Thanks for your kind words. I don't see all the code but perhaps you want to
check if intSelTxtBx has a value of 4 or more before you select the shapes.

old man
 
M

Mona-ABE

That's an excellent point...I'll add that line of code.
if intSelTxtBx >= 4 then
...
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top