简体   繁体   English

如何在MS Power Point演示文稿的一张主幻灯片中添加自定义文本占位符,并为每张幻灯片使用VBA脚本对其进行访问?

[英]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. 我在Power Point演示文稿中的一张幻灯片上创建了一个自定义占位符,即“文本框类型”的“ CustomHeader”。 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. 它还将Section插入到幻灯片的页脚中。 I would like to enter something in the CustomHeader placeholder to every matching slide. 我想在CustomHeader占位符中为每个匹配的幻灯片输入一些内容。

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". 由于您无法在幻灯片上添加占位符,因此我想您是指已在“幻灯片母版”中的“自定义布局”中添加了一个文本占位符,并且已将该占位符重命名为“ CustomHeader”。

When a slide based on that layout is added to the presentation your placeholder will no longer be called "CustomHeader". 将基于该布局的幻灯片添加到演示文稿后,您的占位符将不再称为“ CustomHeader”。 Instead it will be called something like "Text Placeholder 3". 而是将其称为“文本占位符3”。 So your first task is to find the name PowerPoint gives your placeholder when it is inserted. 因此,您的首要任务是查找PowerPoint在插入时为您的占位符提供的名称。

Then you can simply include an extra condition within your loop: 然后,您可以在循环中简单地包含一个额外条件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于Powerpoint(VBA)所有幻灯片中的每个文本框 - For each text box in all slides of power point (VBA) 我想使用 vba 编辑现有幻灯片中的文本 - I want to edit a text in the existing power point slide using vba 如何使用vba附加excel工作簿以在power point中滑动 - How to attach a excel workbook to slide in power point using vba 如何使用VBA宏在Powerpoint幻灯片中“重置图片”? - How to “Reset Picture” in Power point Slide using VBA macro? 如何使用vba获得power point slide尺寸? - How to get power point slide dimension using vba? VBA 宏可在每张幻灯片中添加任意数量的带有图片的幻灯片 - VBA macro to add any number of slides with a picture in each slide Powerpoint幻灯片:如何将我在一张幻灯片上的组合框和文本框控件复制到另一张相同演示文稿的幻灯片上? - Powerpoint slides: how to copy my combobox and textbox controls on one slide to a another slide, same presentation? 如何在演示文稿中循环幻灯片,将新的Excel范围粘贴到每张幻灯片中的表格中 - How to loop through slides in a presentation, pasting a new Excel range into a table in each slide 在VBA powerpoint中如何将新幻灯片添加到空的演示文稿中 - in VBA powerpoint How to add a new slide to an empty presentation 如何通过VBA访问自定义布局幻灯片 - How to access custom Layout Slides through VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM