VBA Powerpoint 2010替换页眉和页脚中的文本

VBA Powerpoint 2010替换页眉和页脚中的文本,vba,excel,powerpoint,powerpoint-2010,Vba,Excel,Powerpoint,Powerpoint 2010,替换PowerPoint模板页眉/页脚中的[DOCID#]代码时遇到问题。我注意到在PowerPoint对象浏览器中,页眉和页脚出现在演示文稿的多个部分(SlideMaster、NotesMaster、HandoutMaster、TitleMaster,然后是每个幻灯片)。我正在运行XL中的代码,并对PowerPoint库进行了引用 Set ppPres = ppApp.Presentations.Open(sTemplate) Set ppMaster = ppPres.Sli

替换PowerPoint模板页眉/页脚中的[DOCID#]代码时遇到问题。我注意到在PowerPoint对象浏览器中,页眉和页脚出现在演示文稿的多个部分(SlideMaster、NotesMaster、HandoutMaster、TitleMaster,然后是每个幻灯片)。我正在运行XL中的代码,并对PowerPoint库进行了引用

   Set ppPres = ppApp.Presentations.Open(sTemplate)

    Set ppMaster = ppPres.SlideMaster
    With ppMaster.HeadersFooters
        .Footer.Text = Replace(.Footer.Text, "[DOCID#]", sDocID)
    End With
    If ppPres.HasNotesMaster Then
        Set ppMaster = ppPres.NotesMaster
        With ppMaster.HeadersFooters
            .Footer.Text = Replace(.Footer.Text, "[DOCID#]", sDocID)
            .Header.Text = Replace(.Header.Text, "[DOCID#]", sDocID)
        End With
    End If
    If ppPres.HasHandoutMaster Then
        Set ppMaster = ppPres.HandoutMaster
        With ppMaster.HeadersFooters
            .Footer.Text = Replace(.Footer.Text, "[DOCID#]", sDocID)
            .Header.Text = Replace(.Header.Text, "[DOCID#]", sDocID)
        End With
    End If
    If ppPres.HasTitleMaster Then
        Set ppMaster = ppPres.TitleMaster
        With ppMaster.HeadersFooters
            .Footer.Text = Replace(.Footer.Text, "[DOCID#]", sDocID)
        End With
    End If
    For Each ppSlide In ppPres.Slides
        With ppSlide.HeadersFooters
            .Footer.Text = Replace(.Footer.Text, "[DOCID#]", sDocID)
        End With
    Next ppSlide
大部分代码运行,但是讲义和注释主标题不会更改文本,即使监视窗口中的对象已正确调整。在逐步浏览代码并在结尾暂停时,我从PowerPoint功能区打开了“插入页眉/页脚”,发现对话框字段已正确调整,但注释中仍有[DOCID#]代码

我还注意到,从客户提供的模板中,演示文稿可能会有.hastlemaster返回True,但当尝试访问.Footer.Text时,我会收到一个错误(无效对象…)


有什么想法吗?

我稍微调整了您的代码,以使用open ActivePresentation(而不是从模板创建新的演示文稿),其余代码按照您的意愿工作,至少在我的Office 2016环境中是这样。您正在使用哪个版本的Office?它是否完全是最新的修补程序?谢谢JamieG。我把它整理好了。Powerpoint甚至有更多的位置包含在对象浏览器(.CustumLayout和.NotePage…)中不明显显示的页眉和页脚。我还发现“注释”页面上的“插入页眉/页脚”功能区选择实际上是将形状插入到.Slide.NotesPage中,因此我对这些对象执行了常规的.TextRange.Replace,现在对其进行了排序。我稍微调整了代码,以使用open ActivePresentation(而不是从模板创建新的)代码的其余部分按照您的意愿工作,至少在我的Office 2016环境中是这样。您正在使用哪个版本的Office?它是否完全是最新的修补程序?谢谢JamieG。我把它整理好了。Powerpoint甚至有更多的位置包含在对象浏览器(.CustumLayout和.NotePage…)中不明显显示的页眉和页脚。我还发现“注释”页面上的“插入页眉/页脚”功能区选择实际上是将形状插入到.Slide.NotesPage中-因此,我们对这些对象执行了常规的.TextRange.Replace,现在将其排序。