Option Explicit
' This function sorts the order of objects based on the objects area. Largest objects
' will be pushed to the back while smaller objects will be placed in front.
Private Sub BubbleSortByArea(ByVal sr As ShapeRange)
Dim n1 As Long ' inner loop index
Dim n2 As Long ' outer loop index
Dim swap As Integer ' temp variable
Dim aofi() As Integer ' Array of indices to sort
ReDim aofi(1 To sr.Count) ' Allocate
' fill the array with numbers 1 to the number of object
For n1 = 1 To sr.Count
aofi(n1) = n1
Next n1
' perform the sort of the indices
For n2 = 1 To sr.Count - 1
For n1 = n2 + 1 To sr.Count
If sr(aofi(n1)).DisplayCurve.Area > sr(aofi(n2)).DisplayCurve.Area Then
swap = aofi(n1)
aofi(n1) = aofi(n2)
aofi(n2) = swap
End If
Next n1
Next n2
' order the objects based on the area
For n1 = 1 To sr.Count
sr(aofi(n1)).OrderToFront
Next n1
End Sub
Sub Sort()
BubbleSortByArea ActivePage.Shapes.All
End Sub