0
votes

I have a PPT template where i need to select the shapes (both headings and body shape) between the black lines. Please note these shapes can change their top, left,height and width. I want to make it so flexible that even if i add any shape(like subtitle or conclusion) between these black lines, still my code will select the above shapes only(both headings and body).

What i have tried:

1)Using name or id, i selected these shapes but that will not fulfill my objective (Objective: to select a shape and create a copy), so creating a copy will still have a same name, which i don't want.

2)I have defined range(top, left, height and width), but this is static. Can i make it dynamic? Below is the code for range selection -

Sub Add_Row_below()

currentslide = ActiveWindow.Selection.SlideRange.SlideIndex

'Selecting Only Shapes within a specified Range

pTop = 78
pLeft = 18
pHeight = 370
pWidth = 686
Count = 0

Dim slideShapes As Shapes
Dim slideShape As Shape

    'Get shapes for the slide
    Set slideShapes = ActivePresentation.Slides(currentslide).Shapes

    'Remove any existing selection
    ActiveWindow.Selection.Unselect

    'Loop through the shapes
    For Each slideShape In slideShapes

        'Check if shape is within the specified boundary
        If ((slideShape.Top >= pTop And slideShape.Top <= (pTop +pHeight)) _
            And (slideShape.Left >= pLeft And slideShape.Left <= (pLeft + pWidth))) Then

            'Add the shape to the current selection
            slideShape.Select (msoFalse)
            Count = Count+ 1

            'Shrink text when overflow
            slideShape.TextFrame2.AutoSize = msoAutoSizeTextToFitShape

        End If
    Next slideShape

End Sub

Note:- template screenshot is attached. enter image description here

Adding template created after a button click: enter image description here

Adding template containing possible shapes(subtitles and conclusion) between the two lines: enter image description here

1
When asking a question, it helps a lot if you use the same terms that are used in the program.Otherwise, we're guessing at what you refer to. I believe "headings" is the Title placeholder and "body" is the text or content placeholder. Top, Left, Width and Height are the position and size properties, not a range. You can check the Shape.Type, and for placeholders, the PlaceholderFormat.Type to help find the kinds of shapes you're after. Instead of using copy and paste, create a new placeholder that has the same size and type as the one you're trying to copy.John Korchok
Thanks john for your feedback, i will be careful from next time.Akash Vishwakarma
Use ShapeIndex instead of ShapeName after duplicating the shape? Or make a new shape with the same properties of the shape you would want a copy of?Bhavesh Shaha

1 Answers

0
votes

You could search for your lines by their appearance: line width, line weight (I guess .left would be the same)

You can use shape.index

Shape index is unique. Shape Name is not unique.

There should be two of them, so an error check could count and make sure you have your two lines. From there you can easily find anything which is below the upper line and above the lower line.