How can I run a macro to each selected object?

I've created a little macro that does it's thing quite well but I have to select each object individually and keep hitting the macro until I've finished each object. How can I automate the macro to do what it needs to only the selected objects even though there are several other object son the page?

Myron

  • The simplest answer to your questions is to create a loop for each shape in your selection. So something like this:

    Sub LoopSelectedShapes()
        Dim sr As ShapeRange
        Dim s As Shape
        
        Set sr = ActiveSelectionRange
        
        For Each s In sr.Shapes
            s.Fill.ApplyUniformFill CreateRGBColor(Rnd * 255, Rnd * 255, Rnd * 255)
        Next s
    End Sub
    

    A few things to note about this approach. A group of shapes is going to be returned as one shape so you will change the color of all shapes in the group to the shape color. If you have a shape inside a powerclip it will be ignored and not change colors.

    Happy Coding.

    -Shelby