简体   繁体   中英

How to add a custom Text placeholder in one of the master slides in MS Power Point presentation and access it using VBA Script for each slide?

I have created a custom placeholder namely "CustomHeader" of Text Box Type on one of the slides in my Power Point presentation. How can I iterate through all slides inserting the Presentation Title into this placeholder.

I have the following code, which enters the Page No in a custom format in the footer. It also inserts the Section to the footer of the slides. I would like to enter something in the CustomHeader placeholder to every matching slide.

Sub SecFootNew()

Dim oshp As Shape
Dim b_found As Boolean
If ActivePresentation.SectionProperties.Count > 0 Then


Dim osld As Variant

For iSlide = 1 To ActivePresentation.Slides.Count
    ' Need Help with These
    With ActivePresentation.Slides(2).Shapes.Placeholders(CustomHeader).TextFrame.TextRange
        .Text = "Happy Honika"
    End With

    ' The Following portion of the code is working Perfectly
    If iSlide <> 1 Then
        Set osld = ActivePresentation.Slides(iSlide)

        ' Configure Display of Page Number
        With osld.HeadersFooters.DateAndTime
            .Visible = False ' True For making the Date Visible
'            .UseFormat = True
'            .Format = ppDateTimedMMMyy
        End With

        ' Configure Footer
        osld.HeadersFooters.Footer.Visible = True
        osld.HeadersFooters.SlideNumber.Visible = True

        For Each oshp In osld.Shapes
        If oshp.Type = msoPlaceholder Then
            If oshp.PlaceholderFormat.Type = ppPlaceholderFooter Then
                With oshp.TextFrame.TextRange
                    .Font.Name = "Calibri"
                    .Font.Size = 12
                    .Font.Color = RGB(255, 255, 255)
                    .Text = ActivePresentation.SectionProperties.Name(osld.sectionIndex)
                End With
            End If
            If oshp.PlaceholderFormat.Type = ppPlaceholderSlideNumber Then
                With oshp.TextFrame.TextRange
                    .Font.Name = "Calibri"
                    .Font.Size = 12
                    .Font.Color = RGB(255, 255, 255)
                    .Text = "Slide " & CStr(osld.SlideIndex) & " of " & CStr(ActivePresentation.Slides.Count)
                End With
            End If
        End If

        Next oshp
    End If
Next iSlide
End If
End Sub

As you can't add placeholders to slides I assume you mean that you have added a Text Placeholder to one of the Custom Layouts in the Slide Master and you have renamed that placeholder "CustomHeader".

When a slide based on that layout is added to the presentation your placeholder will no longer be called "CustomHeader". Instead it will be called something like "Text Placeholder 3". So your first task is to find the name PowerPoint gives your placeholder when it is inserted.

Then you can simply include an extra condition within your loop:

if oshp.Name = "Text Placeholder #" then _
    oshp.TextFrame.TextRange.Text = "Happy Honika"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM