Having some VBA trouble with selections. The code below will select an ellipse in a group of selected shapes, but as soon as I use it with other (unselected) ellipse shapes on the same layer or page it selects the ellipse that is at the top of the layer heirarchy.
Sub Macro1() Dim OrigSelection As ShapeRange Set OrigSelection = ActiveSelectionRange Set s = ActivePage.FindShape(Type:=cdrEllipseShape) s.CreateSelectionEnd Sub
All I want to do is select the ellipse, or other named cdrShape from the currently selected shapes or group, not from the entire page or layer. Logically I would have assumed I just change ActivePage to ActiveSelection, but that doesn't work.
I'm sure this is simple but I cannot figure it out. Can anyone please point me in the right direction to selecting a cdrShape from the currently selected shapes or group.
ActiveSelection is a ShapeActiveSelectionRange is a ShapeRange
If you wish to work with the first matching shape in the selected ShapeRange, then you could use something likeset s = ActiveSelectionRange.Shapes.FindShape (Type:=cdrEllipseShape).
If all you want to do with it is to create a selection, then it could all be done in one line:
Eskimo...Both are exactly what I was looking for. I tried ActiveSelection and ActiveSelectionRange instead of ActivePage, but I excluded Shapes.
Thanks for the clarification. It's appreciated.
Just for clarification and future reference.
For the two examples above to work, In CD12 ActiveSelectionRange was changed to ActiveSelection
If there is more than one ellipse in the selection the above will select the ellipse that was originally selected last.
Changing FindShape to FindShapes selects all ellipses in the selection.
I'm still curious why Shapes is required after ActiveSelection but not after ActivePage ?
Also,, is it possible for the above to be altered to always select the shape that was highest in the layer heirarchy rather than last shape selected?