Group Method

Microsoft Publisher Visual Basic

object.

expression.Group

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

The specified range must contain more than one shape, or an error occurs.

Because a group of shapes is treated as a single shape, grouping and ungrouping shapes changes the number of items in the Shapes collection and changes the index numbers of items that come after the affected items in the collection.

Example

This example adds two shapes to the first page of the active publication, groups the two new shapes, sets the fill for the group, rotates the group, and sends the group to the back of the drawing layer.

With ActiveDocument.Pages(1).Shapes

    ' Add two shapes to the page.
    .AddShape(Type:=msoShapeCan, _
        Left:=50, Top:=10, Width:=100, Height:=200).Name = "shpOne"
    .AddShape(Type:=msoShapeCube, _
        Left:=150, Top:=250, Width:=100, Height:=200).Name = "shpTwo"

    ' Group the shapes and change the formatting for the whole group.
    With .Range(Index:=Array("shpOne", "shpTwo")).Group
        .Fill.PresetTextured PresetTexture:=msoTextureBlueTissuePaper
        .Rotation = 45
        .ZOrder ZOrderCmd:=msoSendToBack
    End With

End With