How to determine the placeholder used?

Given a slide, how can I find out if all slide layout placeholders are used in PowerPoint?

Is it possible to prevent the automatic use of a placeholder when adding an image if this placeholder is not used?

+3
source share
2 answers

You will need to skip all the placeholders on the slide, identify each one, and then check if it is filled with the expected format. There are 18 , so you will need to install them all, but the following is an example of what you can do to check if a placeholder is being used. PpPlaceholderType

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

, , , , , - , , .

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
+1

, , , :

if (selectedSlide.Shapes.Placeholders[i].PlaceholderFormat.ContainedType != Microsoft.Office.Core.MsoShapeType.msoAutoShape)

ContainedType msoAutoShape, . , , , , msoPicture.

Office ( ), ppPlaceholderPicture.

+1

Source: https://habr.com/ru/post/1753189/


All Articles