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