xlmaster
xlmaster

Reputation: 721

vba powerpoint object paramateres for each loop error

I write the code below in ppt vba, for taking, in each slide, each shapes height, top, left, width paramateres. Then my idea is to copy the same paramateres in vba from excel for copying and pasting the OLEObjects to the exact same places on the slide. But gives error on mentioned line below. Any ideas why? I am looking for a reason, why it gives the error; For each sh In ActivePresentation.Slides.Shapes. The data member or method was not found..

Sub chngshp()
Dim sl As Slides
Dim sh As Shapes
Set sl = ActivePresentation.Slides
Set sh = ActivePresentation.Shapes
For each sl In ActivePresentation
For each sh In ActivePresentation.Slides.Shapes
Debug.Print ActivePresentation.Slides.Shapes.Name
Debug.Print ActivePresentation.Slides.Shapes.Height
Next
Next
End Sub

Upvotes: 0

Views: 68

Answers (1)

John Korchok
John Korchok

Reputation: 4913

The set statements are not needed. Here's how your code should be written:

Sub chngshp()
    Dim sl As Slide
    Dim sh As Shape

    For each sl In ActivePresentation.Slides
        For each sh In sl.Shapes
            Debug.Print sh.Name
            Debug.Print sh.Height
        Next sh
    Next sl
End Sub

Upvotes: 1

Related Questions