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 objects on 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
If you replace the line s.Fill.ApplyUniformFill CreateRGBColor(Rnd * 255, Rnd * 255, Rnd * 255) with the "essential" code from the macro (and check that it uses s as the shape to work on, or amend it accordingly), it should process each of the selected shapes consecutively, one at a time.
If that isn't clear, it may be easier if you can post the current macro.
Myron,
If your macro is still treating everything as one shape then it is looking for the selection. So You would want to do something like this:
Sub LoopSelectedShapes() Dim sr As ShapeRange Dim s As Shape Set sr = ActiveSelectionRange For Each s In sr.Shapes s.CreateSelection Macro208 Next s End Sub
The better way to do this is actually pass the shape to your macro:
Sub LoopSelectedShapes() Dim sr As ShapeRange Dim s As Shape Set sr = ActiveSelectionRange For Each s In sr.Shapes Macro208 s Next s End Sub Sub Macro208(s As Shape) s.Fill.ApplyUniformFill CreateRGBColor(Rnd * 255, Rnd * 255, Rnd * 255) 'And all my secret amazing stuff End Sub
This of course requires that you modify your macro to except a shape and not rely on the current selection. ;-)
Hope that helps,