25.2. WOrking with Headers and Footers

PowerPoint uses HeaderFooter objects to represent the headers, footers, slide numbers, and date and time on slides. The HeaderFooter objects are organized into the HeadersFooters collection, which you access through the HeaderFooters property of the Master object, a Slide object, or a SlideRange collection.

Be warned: before you can execute the following code examples, you must first add a footer to the slides in your active presentation . The code examples expect to modify an existing footer, not create it. So, before executing these examples, click the Office button in PowerPoint, and click the New button in the left pane to open the New Presentation dialog box. Click the Installed Templates option in this dialog box and double-click one of the templates, such as Pitchbook, so you'll have some slides to work with in the example code. However, Pitchbook has no footers, so before trying the following code examples, click the Insert tab on PowerPoint's Ribbon, and then in the Text area, click the Header and Footer button to open the Header and Footer dialog box. In this dialog box click the Date and Time check box and the Footer check box. Then click the Apply to All button.

25.2.1. Returning the Header or Footer Object You Want

To return the object you want, use the appropriate property of the HeaderFooter object:

  • Use the DateAndTime property to return the date and time.

  • Use the Footer property to return the footer.

  • Use the Header property to return the header on a notes page or handout. Slides can't have a header.

  • Use the SlideNumber property to return the slide number on a slide or the page number on a notes page or a handout.

The following example uses the Footer property to set the text of the HeaderFooter object of the first slide in the active presentation:

ActivePresentation.Slides(1).HeadersFooters.Footer.Text = "Sentence 102"

25.2.2. Displaying or Hiding a Header or Footer Object

To display the HeaderFooter object, set its Visible property to msoTrue (or just True). To hide the HeaderFooter object, set its Visible property to msoFalse. For example, the following statement hides the footer on the fifth slide in the active presentation:

ActivePresentation.Slides(5).HeadersFooters.Footer.Visible = msoFalse

25.2.3. Setting the Text in a Header or Footer

To set the text that you want in a HeaderFooter object, assign a string containing the text to the object's Text property. For example, the following statement sets the text of the footer of the fifth slide in the active presentation to Confidential:

ActivePresentation.Slides(5).HeadersFooters.Footer.Text = "Confidential"

If you executed the previous example code, executing this example will trigger an error message. That's because you made the same slide (#5) invisible in the previous code. To be able to set the text in this slide, it must first be visible:

ActivePresentation.Slides(5).HeadersFooters.Footer.Visible = msoTrue
ActivePresentation.Slides(5).HeadersFooters.Footer.Text = "Confidential"

25.2.4. Setting the Format for Date and Time Headers and Footers

If your slides, notes pages, or handouts use dates and times in their footers or headers, use the Format property to specify how the dates and times should appear. Table 25.2 lists the constants you can use.

Table 25.2. Format Property Constants for Date and Time Headers and Footers
FormatExample
ppDateTimeddddMMMMddyyyyThursday, October 05, 2008
ppDateTimedMMMMyyyy5 October 2008
ppDateTimedMMMyy5-Oct-08
ppDateTimeHmm10:17
ppDateTimehmmAMPM10:17AM
ppDateTimeHmmss10:17:16
ppDateTimehmmssAMPM10:17:16AM
ppDateTimeMdyy10/5/2008
ppDateTimeMMddyyHmm10/5/2008 10:17AM
ppDateTimeMMddyyhmmAMPM10/5/2008 10:17:16AM
ppDateTimeMMMMdyyyyOctober 5, 2008
ppDateTimeMMMMyyOctober 08
ppDateTimeMMyyOct-08

Set the UseFormat property of the HeaderFooter to msoTrue if you want the date and time to be updated automatically. Set UseFormat to msoFalse if you want the date and time to remain unchanged.

The following section shows an example of using the UseFormat property and the format property of a HeaderFooter object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.54.139