VBA Powerpoint 2010 replacing text in Headers and Footers

£可爱£侵袭症+ 提交于 2019-12-08 07:35:40

问题


Having a challenge replacing a [DOCID#] code in the header/footer of a PowerPoint template. I notice within the PowerPoint object browser that headers and footers are found in a number of parts of a Presentation (SlideMaster, NotesMaster, HandoutMaster, TitleMaster, and then each individual Slide). I'm running the code from in XL, and have Dim'ed with references to the PowerPoint Library.

   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

The code for the most part runs, however the Handout and Notes Master Headers don't change the text, even though the object in the watch window is correctly adjusted. When stepping through the code and pausing at the end, I open the Insert Header/Footers from the PowerPoint ribbon, and find the dialogue box fields correctly adjusted, however the Notes still have the [DOCID#] code.

I've also noticed, from a customer supplied template, that a presentation can have .HasTitleMaster return True, but when trying to access the .Footer.Text I get an error (invalid object...)

Any ideas?

来源:https://stackoverflow.com/questions/35739457/vba-powerpoint-2010-replacing-text-in-headers-and-footers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!