Modify shapes in ALL SLIDES based on a specific shape name

I would like to use VBA to apply a specific "Top", "Left", and "Width" dimensions in all slides that have an embedded excel object.

I tried to accomplish this by running this code, but it's not working.  Any expert advice on how to get this to work?

Sub UpdateShapes()
    
    Dim SlideToCheck As Slide
    Dim ShapeIndex As Integer
    Dim shp As Shape

    For Each SlideToCheck In ActivePresentation.Slides

    
        For ShapeIndex = SlideToCheck.Shapes.Count To 1 Step -1
        
        If shp.Name Like "Object%" Then
        
            SlideToCheck.Shapes(ShapeIndex).Top = 90
            SlideToCheck.Shapes(ShapeIndex).Left = 90
            SlideToCheck.Shapes(ShapeIndex).Width = 500
        
        End If
            
        Next
    Next
End Sub

Open in new window

Sample.pptx
KP_SoCalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
Use * instead of % in VBA to specify the wildcard of "Zero or more characters"

If shp.Name Like "Object*" Then

Open in new window


VBA Wildcards
1
GrahamSkanRetiredCommented:
Since they all have the same name you don't need to use wildcarding. If you were to add other similar shapes to any of the slides, that could cause some confusion.

Also you can address a shape in a Shapes collection by name, so you don't have to step through all the shapes on a slide.
Sub UpdateShapes()
    Dim SlideToCheck As Slide
    
    For Each SlideToCheck In ActivePresentation.Slides
        With SlideToCheck.Shapes("Object 2")
            .Top = 90
            .Left = 90
            .Width = 500
        End With
    Next SlideToCheck
End Sub

Open in new window

1
KP_SoCalAuthor Commented:
This  looks like it will accomplish exactly what I need, but I will need to use a wild card for object name since they will all have different names in my actual file.  Could you tell me how I'd modify this to accommodate it?

With SlideToCheck.Shapes("Object 2")

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GrahamSkanRetiredCommented:
If you are sure that you only have one shape on each file whose name starts with "Object" then use NerdsOfTech's modification of your method.

Otherwise you will need a list that matches the name with the slide number (or slide name)
0
NerdsOfTechTechnology ScientistCommented:
A With statement allows you to reference an item and reduce redundancy. Here's your code with the wildcard (corrected from % to *) and the implementation of a with statement:

Sub UpdateShapes()
    
    Dim SlideToCheck As Slide
    Dim ShapeIndex As Integer
    Dim shp As Shape

    For Each SlideToCheck In ActivePresentation.Slides   

        For ShapeIndex = SlideToCheck.Shapes.Count To 1 Step -1        

	        If shp.Name Like "Object*" Then

        		With SlideToCheck.Shapes(ShapeIndex)
				.Top = 90
            			.Left = 90
	            		.Width = 500
        		End With

	        End If    

        Next

    Next

End Sub

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KP_SoCalAuthor Commented:
1000 apologies for the delay in response.  I've been traveling quite a bit, but i really appreciate the advice on this.  It will make my life a lot more efficient.  Have a terrific weekend.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.