Select all shapes of a given color

  • Thread starter Thread starter quickquestion
  • Start date Start date
Q

quickquestion

Is it possible through vba to select every shape on a slide that is a
certain shade of blue while leaving the other colors deselected?

I figure I can make an array that holds the shape numbers of all the
shapes that match a condition, and then select that array when I'm
done.

I'm wondering if there is an easier way, that I can just add the shapes
that match to the selection one at a time?
Thanks
Sorry if you get this question all the time.
 
Is it possible through vba to select every shape on a slide that is a
certain shade of blue while leaving the other colors deselected?

Generally you don't *want* to select anything in VBA. It's slow, causes all kinds of
screen madness, is slow, and it doesn't work during slide shows. And it's slow.

Did I mention that it's slow? It is.

A shape range is more or less the same as a selection from a programming point of view,
but doesn't require anything to be selected.

This will create a range from the shapes on slide 5 that match a certain condition (red
fill in this case); you can later modify the range however you like (change the color to
green here).

Sub Example()

Dim oRng As ShapeRange
Dim ShapeNameArray() As String
Dim oSh As Shape
Dim oSl As Slide

' Add first element to array (or UBOUND errors in some versions of PPT)
ReDim ShapeNameArray(1 To 1) As String

Set oSl = ActivePresentation.Slides(5)
For Each oSh In oSl.Shapes
If oSh.Fill.ForeColor.RGB = RGB(255, 0, 0) Then
' add its name to the array
ShapeNameArray(UBound(ShapeNameArray)) = oSh.Name
' add an element to the array
ReDim Preserve ShapeNameArray(1 To UBound(ShapeNameArray) + 1) As String
End If
Next ' oSh

' Array now has one more element than needed so delete it
ReDim Preserve ShapeNameArray(1 To UBound(ShapeNameArray) - 1) As String

Set oRng = oSl.Shapes.Range(ShapeNameArray)

' and do something with the range to prove it worked
oRng.Fill.ForeColor.RGB = RGB(0, 255, 0)

End Sub
 
Shyam Pillai said:
Use the following example and edit it as fit.

Find and replace one color with another on fills, text and borders:
http://skp.mvps.org/pptxp006.htm

Regards,
Shyam Pillai

Thanks a lot Mr. Pillai

I was a little unclear in how I described the problem.

I would like to return the user a selection of all blue items on a
page (for example, or all items larger than a certain size or all of a
certain type of autoshape)

I guess I could make an array that holds the item numbers of all the
items that fit.

I'm just wondering if it is possible to directly

for each shp in activeview.something.slide
if shape_matches_criteria
add shape to selection or add shape to range
end if
next shp

range.select 'if we added the shape to a range

and skip over any array business, just for simplicity's sake.
 
Back
Top