Determining relative order of two objects?

I'm looking for some way to determine the relative order of objects. So, given Object A and Object B, I want to know which one is in front of the other.

I'm aware that I can change the order, e.g., deliberately move Object A immediately in front of or immediately behind Object B, but that's not what I want to do.

My immediate goal here is to be able to change the order to put a particular object behind a specified shaperange (e.g., put it immediately behind the "back-most" shape in a shaperange).

No Data
  • You can see here I have three rectangles that are overlapping so that you can see the stack order:

    Using the Objects Manger to name each Shape like this:

    If I typed this into the Immediate window:


    Its going to return: Red

    If I typed this into the Immediate window:


    It is going to return: Blue

    If you shift select the shapes, blue, red and then green type:


    It is going to return: Green

    That is why I will often use a little CQL to sort the ShapeRange so that I know it is always in the stacking order and not the selection order. So I would do something like this:

    Dim srSelection As ShapeRange

    Set srSelection = ActiveSelectionRange
    srSelection.Sort " <"
    Debug.Print srSelection.FirstShape.Name

    Which is going to output: Red

    Hopefully that little trick helps. Happy coding, 


No Data