views:

45

answers:

1

Given a slide how can one figure out if all the slide layout placeholders are in use in PowerPoint?

Can one prevent auto usage of a placeholder when adding a picture if that placeholder is not in use?

+1  A: 

You would need to loop through all the placeholders on the slide, determine each one's type and then check to see if it is filled with the format that expected. There are 18 PpPlaceholderType, so you'd have to set them all up, but the below is a sample of what you can do to check to see if a placeholder is in use.

Sub CheckPlaceholders()
Dim ap As Presentation: Set ap = ActivePresentation
Dim sl As Slide: Set sl = ap.Slides(2)
Dim shs As Shapes: Set shs = sl.Shapes
Dim ph As Placeholders: Set ph = shs.Placeholders
Dim p As Shape
    For Each p In ph
        Select Case p.Type
        Case PpPlaceholderType.ppPlaceholderHeader
            If p.TextFrame.HasText Then
                Debug.Print "This Placeholder is in use"
            End If
        Case PpPlaceholderType.ppPlaceholderChart
            If p.HasChart Then
                Debug.Print "This Placeholder is in use"
            End If
        End Select
    Next
End Sub

To insert, say, a picture and not have it arrive in a placeholder, the only way I've found is to create a loop to add pictures until one of them is out of a placeholder and then delete the ones already inserted.

Sub AddPicture()
    Dim pic As String
    pic = "C:\Users\Me\Desktop\beigeplum.jpg"
    Dim ap As Presentation: Set ap = ActivePresentation
    Dim sl As Slide: Set sl = ap.Slides(1)
    Dim sh As Shape

    Do
        Set sh = sl.Shapes.AddPicture(pic, msoFalse, msoTrue, 1, 1)
        sh.Tags.Add "MYPICTURE", 0
    Loop Until sh.Type <> 14

    Dim p As Shape
    For Each p In sl.Shapes
        If p.Type = 14 Then
            If p.Tags.count > 0 Then
                If p.Tags.Name(1) = "MYPICTURE" Then
                    p.Delete
                End If
            End If
        End If
    Next
End Sub
Otaku
I was aware of this solution, I was looking for a more elegant one.As for automatic usage of placeholder, just try to add an object to a slide with layout - ppLayoutObject say viaactiveSlide.Shapes.AddPicture(...);
Yeah, since PPT2007 everything has gotten a bit weird with the placeholders. The solution you mentioned in your other post is one way to do it, but you're right, it has draw-backs when the old slidelayout is re-applied. The only way that I've found is kind of hacky. See update above.
Otaku
On the placeholder usage, this is about as elegant as it gets :(
Otaku