Sub AlignShapesOrGroup()
Dim selectedShapes As ShapeRange
Dim groupedShape As Shape
' 現在選択されている図形を取得
Set selectedShapes = ActiveWindow.Selection.ShapeRange
' 選択された図形が2個以上の場合
If selectedShapes.Count > 1 Then
' 図形をグループ化
Set groupedShape = selectedShapes.Group
' 左右に整列
selectedShapes.Align msoAlignCenters, True
' グループ化を解除
groupedShape.Ungroup
ElseIf selectedShapes.Count = 1 Then
' 選択している図形が1つの場合、左右に整列
selectedShapes.Align msoAlignCenters, True
Else
MsgBox "図形が選択されていません。図形を選択して再度マクロを実行してください。", vbExclamation
End If
End Sub