Sub 左合わせ()

    Dim shpZ As Shape

    Dim shp As Shape

    Dim i As Integer

    Dim diff As Single

    

    ' 選択された図形の数を確認

    If ActiveWindow.Selection.ShapeRange.Count < 2 Then

        MsgBox "選択された図形が2つ未満です。2つ以上の図形を選択してください。"

        Exit Sub

    End If

    

    ' 最後に選択された図形を取得し、図形Zとして設定

    Set shpZ = ActiveWindow.Selection.ShapeRange.Item(ActiveWindow.Selection.ShapeRange.Count)

 

    ' 選択されたすべての図形の左辺を、図形Zの左辺に合わせる

    For i = 1 To ActiveWindow.Selection.ShapeRange.Count - 1

        Set shp = ActiveWindow.Selection.ShapeRange.Item(i)

        

        If Not (shp Is Nothing) And Not (shpZ Is Nothing) Then

            ' 差を計算してshpの位置を調整

            diff = shp.Left - shpZ.Left

            shp.Left = shpZ.Left

            shp.Width = shp.Width + diff

        Else

            MsgBox "図形の取得に失敗しました。"

            Exit Sub

        End If

    Next i

 

End Sub