Article ID: 161958
Article Last Modified on 1/19/2007
Sub UnGroupShapes()
Dim sShape1 As Shape
Dim sShape2 As Shape
' Create new blank document.
Application.Documents.Add
' Create two shapes(Hexagon and Heart).
With ActiveDocument.Shapes
' Add Hexagon shape.
Set sShape1 = .AddShape(10, 122.4, 79.2, 72#, 72#)
' Add Heart shape.
Set sShape2 = .AddShape(21, 230.4, 79.2, 72#, 72#)
End With
' Select both shapes.
sShape1.Select
' The (0) argument in the following command allows
' selection of the second shape without deselecting
' the first shape.
sShape2.Select (0)
With Selection.ShapeRange
' Group the shapes.
.Group.Select
' UnGroup the shapes and leave them selected.
.Ungroup.Select
End With
End Sub
To have this code work properly, you can have the last two
lines resemble the following sample (which groups the objects, reselects
them, ungroups the objects, and then deselects them):
' Group the shapes. Selection.ShapeRange.Group.Select ' UnGroup the shapes and leave them deselected. Selection.ShapeRange.UngroupOr you can use code similar to the following, as in the "Ungroupshapes" example (which groups the objects, selects them, ungroups the objects, and then leaves them selected):
' Group the shapes. Selection.ShapeRange.Group.Select ' UnGroup the shapes and leave them selected. Selection.ShapeRange.Ungroup.SelectFor more information about grouping and ungrouping shapes, from the Visual Basic Editor, click the Office Assistant, type "ShapeRange," click Search, and then click to view "ShapeRange Collection Object."
176476 OFF: Office Assistant Not Answering Visual Basic Questions
173707 OFF97: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbdtacode kberrmsg kbprb KB161958