[英]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?
我在Power Point演示文稿中的一張幻燈片上創建了一個自定義占位符,即“文本框類型”的“ CustomHeader”。 如何遍歷將演示文稿標題插入此占位符的所有幻燈片。
我有以下代碼,該代碼在頁腳中以自定義格式輸入頁面編號。 它還將Section插入到幻燈片的頁腳中。 我想在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
由於您無法在幻燈片上添加占位符,因此我想您是指已在“幻燈片母版”中的“自定義布局”中添加了一個文本占位符,並且已將該占位符重命名為“ CustomHeader”。
將基於該布局的幻燈片添加到演示文稿后,您的占位符將不再稱為“ CustomHeader”。 而是將其稱為“文本占位符3”。 因此,您的首要任務是查找PowerPoint在插入時為您的占位符提供的名稱。
然后,您可以在循環中簡單地包含一個額外條件:
if oshp.Name = "Text Placeholder #" then _
oshp.TextFrame.TextRange.Text = "Happy Honika"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.