1

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?

JJW
  • 11
  • 3
  • I tweaked your code slightly to use the open ActivePresentation (instead of creating a new one from a template) and the rest of the code works as you intend, at least in my Office 2016 environment. Which version of Office are you using and is it fully up to date with patches? – Jamie Garroch - MVP Mar 02 '16 at 09:53
  • Thanks JamieG. I got it sorted. Powerpoint has even more positions that hold headers and footers that aren't obviously displayed in the object browser (.CustumLayout and .NotePage...). I also found that the Insert Header/Footer Ribbon selection on the Notes page actually inserts shapes into the .Slide.NotesPage - So have done the conventional .TextRange.Replace on these objects and now have it sorted. – JJW Mar 03 '16 at 23:44

0 Answers0