none
Powerpoint - VBA - Manipulating shapes inside placeholder shapes (via VBA) RRS feed

  • Question

  • I need to read /write all texts in PPT presentations.
    All goes well except for shapes (mostly tables) inside placeholder objects.
    I've been trying to find out how to manipulating shapes inside placeholder shapes, but without success.

    The closest post I've seen to my problem is
    http://stackoverflow.com/questions/3568412/powerpoint-getting-the-original-shape-from-inside-a-placeholder-programatical
    Mr. Otaku suggested using SmartArtQuickStyle to get at the object inside the placeholder, but all the documentation I looked at for SmartArtQuickStyle have me no clue.

    Could someone please give me a clue?
    Thanks so much,
    JSvendsen
    Powerpoint 2010

    Saturday, April 21, 2012 11:48 PM

Answers

  • Hello,

    PPT 2007 and later have the ContainedType property on the PlaceholderFormat which will tell you what type of shape is contained within the placeholder. Once you know what type is contained then the rest of the processing is just like any other shape.

    Assuming shp has a reference to a placeholder shape then the line below will give you info on the type within it

    Debug.Print shp.PlaceholderFormat.ContainedType

    To give you a better understanding:

    Sub Test()
    Dim shp As Shape
    Dim sld As Slide

    Set sld = ActivePresentation.Slides(1)

    ' Look for placeholders containing tables on the 1st slide of the presentation

    For Each shp In sld.Shapes.Placeholders
        If shp.PlaceholderFormat.ContainedType = msoTable Then

        'If we find one pass the shape reference to the routine that is enumerating the text

            Call EnumerateTableText(shp)
        End If
    Next

    End Sub

    Sub EnumerateTableText(shp As Shape)
    Dim row As Long
    Dim column As Long

    For row = 1 To shp.Table.Rows.Count
        For column = 1 To shp.Table.Columns.Count
            Debug.Print shp.Table.Cell(row, column).Shape.TextFrame2.TextRange.Text
        Next
    Next

    End Sub


    Regards, Shyam (http://skp.mvps.org)



    Sunday, April 22, 2012 4:57 PM