更新所有幻灯片母版和布局的页脚

Update all slide master's and layout's footers

正在尝试创建一个宏以快速将项目名称输入到 ppt 页脚。我只能让顶级幻灯片母版接受输入标题。我尝试使用新的页脚信息遍历其他幻灯片母版布局,但在 For 循环

中将文本写入页脚的行中不断出现错误

    Sub footchange()

    Dim myValue As Variant
    Dim sld As Slide

    myValue = InputBox("Enter Presentation Name")

    Set mySlidesHF = ActivePresentation.SlideMaster.HeadersFooters

    'Add name to slide master footer
    With mySlidesHF
        .Footer.Visible = True
        .Footer.Text = myValue + "    |   Confidential © 2020"
        .SlideNumber.Visible = True  
    End With

    'Add name to slide master layouts footers
    For Each sld In ActivePresentation.Slides
       With sld.HeadersFooters
            .Footer.Visible = True 
            .Footer.Text = myValue + "    |   Confidential © 2020"
            .SlideNumber.Visible = True
        End With
    Next

您可以通过 DESIGN 属性 访问其他大师: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.design

这段代码应该可以帮助您入门。如果您遇到问题,请反馈。 (为了更好地理解审稿人而保留的缩进)

Dim myValue As Variant
Dim sld As Slide

'Insert a Design Variable
Dim oMaster As Design

myValue = InputBox("Enter Presentation Name")

'Just to show you how many Masters you have
Debug.Print ActivePresentation.Designs.Count

'Loop through them
For Each oMaster In ActivePresentation.Designs

'Use actual Design
Set mySlidesHF = oMaster.SlideMaster.HeadersFooters

'Add name to slide master footer
With mySlidesHF
    .Footer.Visible = True
    .Footer.Text = myValue + "    |   Confidential © 2020"
    .SlideNumber.Visible = True
End With

'Another approach would be to change the footer on each slide manually
For Each sld In ActivePresentation.Slides
   With sld.HeadersFooters
        .Footer.Visible = True
        .Footer.Text = myValue + "    |   Confidential © 2020"
        .SlideNumber.Visible = True
    End With
Next

Next 'oMaster

我能够通过为每张母版幻灯片中的布局添加第二个嵌套循环来更新所有母版 slides/layouts:

Sub footchange()

Dim myValue As Variant
Dim sld As Slide

'Add design and layout variables
Dim oMaster As Design
Dim cLay As CustomLayout

myValue = InputBox("Enter Presentation Name")

'Just to show you how many Masters you have
Debug.Print ActivePresentation.Designs.Count

'Loop through them
For Each oMaster In ActivePresentation.Designs

'Use actual Design
Set mySlidesHF = oMaster.SlideMaster
Set myLayoutsHF = oMaster.SlideMaster.CustomLayouts


'Add name to slide master footer
With mySlidesHF.HeadersFooters
    .Footer.Visible = True
    .Footer.Text = myValue + "    |   Confidential © 2020"
    .SlideNumber.Visible = True
End With

'Add name to layouts
For Each cLay In myLayoutsHF
    With cLay.HeadersFooters
        .Footer.Visible = True
        .Footer.Text = myValue + "    |   Confidential © 2020"
        .SlideNumber.Visible = True
    End With
Next cLay

Next oMaster


End Sub

我能够通过以下方式访问相应自定义布局的“CaseCode”和“版权”表单来编辑布局页脚:

Dim objPowerPoint As New PowerPoint.Application
 
objPowerPoint.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(8) _
    .Shapes("CaseCode").TextFrame.TextRange.text = "Test"

我用这个作为解决方法,因为上面的解决方案对我不起作用。