How to identify images and Textboxes on Powerpoint VBA?

There is a internet application which creates a series of graphs which are automatically imported on to Powerpoint. So a total of 14 slides are created. Some slide s have only textboxes and some slides have images, and some slides have both.

So I try to record a macro to move the images and textboxes around, and create a new slide with my desired formatting.  I recorded macro and saved it.

I ran the internet application again and generated the graphs. Then went to visual basic editor and insert a new module with the code of the previously recorded macro.
it gives the error of specified item cannot be found.

I am attaching the code below. I assume the name of the textboxes and pictures might be changing each time whic causes problems?

Is this right?
and how can I overcome this problem?

Thanks
Sub Macro4()
'

'
 
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.59, msoFalse, msoScaleFromTopLeft
        .ScaleHeight 0.59, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -70#
        .IncrementTop 8#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 3").Select
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -10#
        .IncrementTop -146#
    End With
    ActiveWindow.Selection.ShapeRange.Delete
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -10#
        .IncrementTop -154#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Group 87").Select
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
        .ScaleHeight 0.91, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 24#
        .IncrementTop 6#
    End With
    ActiveWindow.Selection.ShapeRange.IncrementLeft 6#
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
        .ScaleHeight 0.81, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 6#
        .IncrementTop -12#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.ShapeRange.ScaleHeight 0.85, msoFalse, msoScaleFromTopLeft
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.ShapeRange.Delete
    ActiveWindow.Selection.SlideRange.Shapes("Group 94").Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 26#
        .IncrementTop 232#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Group 90").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 164").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 165").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 166").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 167").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 168").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 170").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 173").Select
    ActiveWindow.Selection.Unselect
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -18#
        .IncrementTop -6.75
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.ShapeRange.IncrementLeft 12#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.64, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.64, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 100#
        .IncrementTop 8#
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -16#
        .IncrementTop -18#
    End With
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.96, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.96, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -18#
        .IncrementTop 18#
    End With
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.96, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.96, msoFalse, msoScaleFromTopLeft
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 184").Select
    ActiveWindow.Selection.ShapeRange.IncrementLeft -6#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 73").Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 8#
        .IncrementTop 394#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 4").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=2, Length:=1).Select
    ActiveWindow.Selection.TextRange.Text = ""
    ActiveWindow.Selection.ShapeRange.Delete
    ActiveWindow.Selection.SlideRange.Shapes("Group 185").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 246").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 247").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 248").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 249").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 250").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 251").Select
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 360#
        .IncrementTop -168#
    End With
    ActiveWindow.Selection.Unselect
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 6#
        .IncrementTop -12#
    End With
    ActiveWindow.Selection.Unselect
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -6#
        .IncrementTop -12#
    End With
    ActiveWindow.Selection.ShapeRange.IncrementLeft 6#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 3").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4", "Picture 5")).Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.57, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.57, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.71, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.71, msoFalse, msoScaleFromTopLeft
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -87.12
        .IncrementTop 296#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 253").Select
    ActiveWindow.Selection.ShapeRange.IncrementLeft -98#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 254").Select
    ActiveWindow.Selection.ShapeRange.IncrementLeft -202#
    ActiveWindow.Selection.SlideRange.Shapes("Picture 255").Select
    ActiveWindow.Selection.ShapeRange.IncrementLeft -306#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 255").Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 255", "Picture 254")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 255", "Picture 254", "Picture 253")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 255", "Picture 254", "Picture 253", "Picture 252")).Select
    ActiveWindow.Selection.ShapeRange.Group.Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 50#
        .IncrementTop 454#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Group 257").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 296").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 297").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 298").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 299").Select
    ActiveWindow.Selection.Unselect
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 6#
        .IncrementTop -12#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.SlideRange.Shapes("Picture 3").Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 3", "Picture 4")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 3", "Picture 4", "Picture 5")).Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -90#
        .IncrementTop 50#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Picture 303").Select
    ActiveWindow.Selection.ShapeRange.Delete
    ActiveWindow.Selection.SlideRange.Shapes("Picture 304").Select
    ActiveWindow.Selection.ShapeRange.Delete
    ActiveWindow.Selection.SlideRange.Shapes("Picture 305").Select
    ActiveWindow.Selection.ShapeRange.Delete
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4", "Picture 5")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4")).Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 86#
        .IncrementTop 68#
    End With
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft -6#
        .IncrementTop 18#
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Picture 2").Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4")).Select
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 2", "Picture 3", "Picture 4", "Picture 5")).Select
    ActiveWindow.Selection.ShapeRange.Group.Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .ScaleWidth 0.68, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 0.56, msoFalse, msoScaleFromTopLeft
    End With
    ActiveWindow.Selection.SlideRange.Shapes("Group 256").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 309").Select
    With ActiveWindow.Selection.ShapeRange
        .Fill.Transparency = 0#
        .Height = 146.12
        .Width = 287.25
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 51").Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 50#
        .IncrementTop 460#
    End With
    ActiveWindow.Selection.ShapeRange.IncrementTop 23.38
    ActiveWindow.SmallScroll Down:=-1
    ActiveWindow.Selection.Unselect
    ActiveWindow.SmallScroll Down:=12
    ActiveWindow.View.GotoSlide Index:=2
    ActiveWindow.SmallScroll Down:=0
    ActiveWindow.View.GotoSlide Index:=1
    ActiveWindow.Selection.SlideRange.Shapes("Group 314").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 314").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 352").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 354").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 355").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 356").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 357").Select
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 294#
        .IncrementTop -47.38
    End With
    ActiveWindow.LargeScroll ToRight:=1
    ActiveWindow.Selection.ShapeRange.IncrementLeft 60#
    ActiveWindow.Selection.ShapeRange.IncrementTop 6#
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 365").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 6").Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 367").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=41).Select
    ActiveWindow.Selection.TextRange.Font.Size = 8
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 256").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 302").Select
    ActiveWindow.Selection.ShapeRange.IncrementTop -12#
    ActiveWindow.Selection.SlideRange.Shapes("Group 256").Select
    ActiveWindow.Selection.ShapeRange.IncrementTop 46.75
    ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Group 302", "Group 256")).Select
    ActiveWindow.Selection.ShapeRange.IncrementTop 36#
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 367").Select
    ActiveWindow.Selection.ShapeRange.ScaleWidth 0.42, msoFalse, msoScaleFromTopLeft
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 92#
        .IncrementTop -68#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.LargeScroll ToRight:=1
    ActiveWindow.Selection.SlideRange.Shapes("Group 309").Select
    ActiveWindow.Selection.SlideRange.Shapes("Group 365").Select
    ActiveWindow.Selection.ShapeRange.IncrementTop 24#
    ActiveWindow.Selection.SlideRange.Shapes("Group 309").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Group 302").Select
    ActiveWindow.Selection.Unselect
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 6").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
    ActiveWindow.Selection.Copy
    ActiveWindow.Selection.Unselect
    ActiveWindow.View.Paste
    ActiveWindow.Selection.ShapeRange.ScaleWidth 0.46, msoFalse, msoScaleFromTopLeft
    ActiveWindow.Selection.ShapeRange.ScaleWidth 1.12, msoFalse, msoScaleFromTopLeft
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 284#
        .IncrementTop -74#
    End With
    ActiveWindow.LargeScroll ToRight:=1
    With ActiveWindow.Selection.ShapeRange
        .IncrementLeft 120#
        .IncrementTop 6#
    End With
    ActiveWindow.Selection.Unselect
    ActiveWindow.Selection.SlideRange.Shapes("Text Box 368").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=41).Select
    ActiveWindow.Selection.TextRange.Font.Size = 8
    ActiveWindow.Selection.ShapeRange.IncrementLeft 24#
    ActiveWindow.Selection.Unselect
    ActivePresentation.Save
End Sub

Open in new window

awesomejohn19Asked:
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.

JSRWilsonCommented:
Maybe if you said what the internet app was?

The code you have is a perfect example of the recorder's useless code!
0
awesomejohn19Author Commented:
It is financial database.
My question is not necessarily about the internet app. My question is how to identify (or get the name of ) each textbox and image.
0
JSRWilsonCommented:
My point is to do this we need to know a lot more about the textboxes and images that have been added.

You are asking the eqivalent of how do I recognise someone I've never met or seen, you need to have something that will identify the particular text or picture. If you know the name(s) you are looking for this will do it!
0
awesomejohn19Author Commented:
The name of the textboxes seem to be Texbox and a number. Can't we go through the controls on the powerpoint with the vba? And according to their location (slide #) identify them?
0
irudykCommented:
Okay, you asked how to identify (or get the name of ) each textbox and image.  The following code will output (in the VBA immediate window) the name for each slide and its applicable shapes.  You could try and use this to parse through the results of the output created by your financial database.
Also, given that the database output will likely vary with each output, you would have to rethink your code.  That is, how you recorded it for one output may (and probably won't) work for all outputs. By using the code below, you can cycle through each slide/shape and possibly make the desired changes you are looking for.

Sub GetShapeNames()
Dim sl As Slide
Dim sh As Shape
For Each sl In ActivePresentation.Slides
    For Each sh In sl.Shapes
        Debug.Print sl.Name & "-" & sh.Name
    Next
Next
End Sub

Open in new window

0

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
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
Visual Basic Classic

From novice to tech pro — start learning today.