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).
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:
?ActivePage.Shapes.All.FirstShape.Name
Its going to return: Red
?ActiveSelectionRange.Shapes.First.Name
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 "@shape1.com.ZOrder < @shape2.com.ZOrder" Debug.Print srSelection.FirstShape.Name
Which is going to output: Red
Hopefully that little trick helps. Happy coding,
-Shelby