如何在MS Power Point演示文稿中的一张母版幻灯片中添加自定义文本占位符,并使用每张幻灯片的VBA脚本访问它



>我在Power Point演示文稿中的一张幻灯片上创建了一个自定义占位符,即"文本框类型的自定义标题"。如何循环访问将演示文稿标题插入此占位符的所有幻灯片。

我有以下代码,它在页脚中以自定义格式输入页码。它还会将节插入到幻灯片的页脚。我想在自定义标题占位符中为每个匹配的幻灯片输入一些内容。

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

由于您无法向幻灯片添加占位符,因此我假设您的意思是您已将文本占位符添加到幻灯片母版中的一个自定义版式中,并且已将该占位符重命名为"CustomHeader"。

基于该版式的幻灯片添加到演示文稿中后,您的占位符将不再称为"自定义标题"。相反,它将被称为"文本占位符 3"之类的东西。因此,您的第一个任务是找到 PowerPoint 在插入占位符时为其提供的名称。

然后,您可以简单地在循环中包含额外的条件:

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

相关内容

最新更新