Set application = GetObject(, "PowerPoint.Application") ' Validate if the properties are provided If WScript.Arguments.Length > 0 Then align_mode = WScript.Arguments(0) align_type = WScript.Arguments(1) Else Call Err.Raise(60003, , "Align properties not provided") End If ' Count the number of shapes selected count = 0 count = application.ActiveWindow.Selection.ShapeRange.Count ' Validate if any shapes are selected If (count < 1) Then Call Err.Raise(60003, , "No shapes selected") End If With application.CommandBars If (align_mode = "ALIGN_TO_SLIDE") Then ' Trigger align to slide .ExecuteMso("ObjectsAlignRelativeToContainerSmart") ElseIf (align_mode = "ALIGN_TO_OBJECTS") Then ' Validate if at least 2 shapes are selected If (count < 2) Then Call Err.Raise(60003, , "For Align to Objects, select at least 2 shapes for Vertical or Horizontal alignment") End If If (count < 3 And (align_type = "VERTICAL" Or align_type = "HORIZONTAL")) Then Call Err.Raise(60003, , "For Align to Objects, select at least 3 shapes for Distribute Vertically or Horizontally") End If ' Trigger align to objects .ExecuteMso("ObjectsAlignSelectedSmart") End If ' Trigger type of alignment Call Align_Vertical_Horizontal() End With Public Sub Align_Vertical_Horizontal() WScript.Echo align_type With application.CommandBars Select Case align_type Case "TOP" .ExecuteMso("ObjectsAlignTopSmart") Case "MIDDLE" .ExecuteMso("ObjectsAlignMiddleVerticalSmart") Case "BOTTOM" .ExecuteMso("ObjectsAlignBottomSmart") Case "LEFT" .ExecuteMso("ObjectsAlignLeftSmart") Case "CENTER" .ExecuteMso("ObjectsAlignCenterHorizontalSmart") Case "RIGHT" .ExecuteMso("ObjectsAlignRightSmart") Case "VERTICAL" .ExecuteMso("AlignDistributeVertically") Case "HORIZONTAL" .ExecuteMso("AlignDistributeHorizontally") End Select End With End Sub