Selection.AddToGroup Method (Visio)

Adds the selected shapes to the selected group.

Version Added: Visio 2.0

expression .AddToGroup

expression A variable that represents a Selection object.

Return Value

Nothing

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.

The following macro shows how to use the AddToGroup method to add selected shapes to a selected group.

Before running this macro, open the Basic Shapes stencil or a document based on the Basic Diagram template.

 
Public Sub AddToGroup_Example() 
 
 Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_U.VSS").Masters.ItemU("Square"), 3, 8 
 
 Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_U.VSS").Masters.ItemU("Pentagon"), 4, 8 
 
 Application.ActiveWindow.SelectAll 
 
 ActiveWindow.DeselectAll 
 ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemU("Pentagon"), visSelect 
 ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemU("Square"), visSelect 
 ActiveWindow.Selection.Group 
 
 Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_U.VSS").Masters.ItemU("Ellipse"), 5, 6 
 
 ActiveWindow.DeselectAll 
 ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemU("Ellipse"), visSelect 
 ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemU("Sheet.3"), visSelect 
 ActiveWindow.Selection.AddToGroup 
 
End Sub 

Show:
© 2014 Microsoft