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

Posted

技术标签:

【中文标题】更新所有幻灯片母版和布局的页脚【英文标题】:Update all slide master's and layout's footers 【发布时间】:2020-09-16 11:39:33 【问题描述】:

尝试创建一个宏来快速将项目名称输入到 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

【问题讨论】:

你得到了什么错误,在哪一行? HeaderFooter(未知成员):第 24 行的请求无效 【参考方案1】:

您可以通过 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

【讨论】:

我仍然遇到与此更新相同的问题。添加设计属性仍然产生相同的结果。第一个主布局发生变化,但尝试更新其他主布局时出错 什么错误?您必须更具体,否则我们根本无法帮助您 HeaderFooter(未知成员):第 24 行的请求无效 代码示例应该让你开始。你用过调试吗?错误所在行的内容是什么? [这是一个视频] (screencast.com/t/SqjSQZEe) 向您展示代码的作用以及它将如何为您指明正确的方向。也许您想将文件上传到云端,以便我们查看。 感谢您深入研究并上传视频。我收到的错误出现在“ .Footer.Text = myValue + " | Confidential © 2020" ”行上,我相信因为将 .footer 属性应用于错误的更高级别的属性,我可以获得要更新的***主幻灯片,但它是给我带来麻烦的嵌套的。这是一张图片,说明了我遇到的问题:imgur.com/a/VogZK60【参考方案2】:

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

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

【讨论】:

【参考方案3】:

我可以通过以下方式访问相应自定义布局的“案例代码”和“版权”表单来编辑布局页脚:

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

我将其用作解决方法,因为上述解决方案对我不起作用。

【讨论】:

以上是关于更新所有幻灯片母版和布局的页脚的主要内容,如果未能解决你的问题,请参考以下文章

如何在PPT中创建自己的幻灯片母版

PPT插入幻灯片编号操作不起作用

PPT插入幻灯片编号操作不起作用

为幻灯片添加自动更新日期和时间

Java 创建并应用PPT幻灯片母版

VS2005 使用了母版页技术,可是点运行后母版页的设计内容无法显示,特别是图片就是空白的,该怎么解决呢