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/