PDA

View Full Version : Select picture shapes



vpager
09-11-2014, 03:46 AM
Hi

Is there a way to select only picture shapes from the Shapes collection?

I believe Shapes represents all shapes, not just pictures. But I need to be able to select all the picture shapes and apply the same formatting to them all.
(The program won't know how many picture shapes there are in any given worksheet it is operating on.)

How would I select only the picture shapes?

Thanks for any help you can give.

Mike

mancubus
09-11-2014, 04:05 AM
hi.

try this:



Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture Then
'additional code here when shape is a picture
End If
Next



msdn source:
MsoShapeType Enumeration (http://http//msdn.microsoft.com/en-us/library/aa432678(v=office.12).aspx)

vpager
09-11-2014, 04:18 AM
Hi mancubus. Appreciate your reply.

I was really looking for a way to select all the relevant shapes as one collection so I could subsequently refer to that collection of shapes at various points in my program to apply formatting etc to all the picture shapes in one go.

Regards
Mike

mancubus
09-11-2014, 04:38 AM
you can create an array or collection and loop each element of that array or collection.

vpager
09-11-2014, 04:53 AM
Thanks for your suggestions. Thought I was missing out on a single-line type selection option.
[Solved]

Regards
Mike

mancubus
09-11-2014, 05:09 AM
welcome.

below deletes shapes that meet the criteria:


Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture Then
shp.Delete
End If
Next

snb
09-11-2014, 06:42 AM
or

Sub M_snb()
For Each sh In Shapes
If sh.Type = 13 Then c00 = c00 & "," & sh.Name
Next

Shapes.Range(Split(Mid(c00, 2), ",")).Delete
End Sub

vpager
09-11-2014, 06:53 AM
Thanks for your thoughts and ideas on this. Must admit, I'd forgotten about the "Dekete" keyword :doh: (Sorry snb, I do appreciate your suggestion; an interesting method.)

My project includes the means to identify and cycle through the required shapes to add pictures and outlines in the first place. So I've simply used the same cycling method to reset them. It's also safer, in case there are any another shapes lurking in the worksheet somewhere that shouldn't be touched.

Regards
Mike