Group Creation

B

Bing

I need to create groups using a value stored in the shapesheet. should the
value be the same then add that shape to a group and then move on to the next
shape. I have done it manually, But having trouble writing a marco that can
do this. Can't seem to find a way to create the group and add the first
object.
 
C

Chris Roth [MVP]

Hi Bing,

You can group a single shape just as well as with multiple shapes -- simply:

Set shpGroup = shp.Group

After you have a group, you can add shapes to a a group using AddToGroup,
but this works on a Selection object. Have a look at this code snippet,
maybe it will help:

Sub MakeAndAddToGroup()

Dim shp1 As Visio.Shape, shp2 As Visio.Shape, shpGrp As Visio.Shape
Dim sel As Visio.Selection

Set shp1 = Visio.ActivePage.DrawRectangle(1, 1, 1.5, 1.5)
Set shp2 = Visio.ActivePage.DrawRectangle(2, 2, 2.5, 2.25)

Set shpGrp = shp1.Group

'// Make an empty selection
Set sel = Visio.ActivePage.CreateSelection(visSelTypeEmpty,
visSelModeOnlySuper)

'// Add shp2 and shpGrp to the selection.
Call sel.Select(shpGrp, Visio.VisSelectArgs.visSelect)
Call sel.Select(shp2, Visio.VisSelectArgs.visSelect)

'// Note about AddToGroup: The current selection must contain
'// both the shapes to add and the group to which you want to
'// add them. The group must be the primary selection or the
'// only group in the selection.
sel.AddToGroup

End Sub





--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 

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