View Full Version : Simple Powerpoint Macro - Remove Page Numbers/Footers/Etc
petersoni
12-15-2009, 09:03 AM
Hi guys,
I am just dabbling in VBA. Here is my situation: I am given a large number of powerpoint files, some of which have dates/page numbers/titles in the headers and footers and some of which don't. I want to strip all headers and footers and print 3 per page handouts, with outlines. I have figured out how to set the print options to print 3 per page and outlines, but I can't seem to get rid of page numbers, dates, and titles. Can you help?
Here's the code I have so far:
Sub print3slides()
ActivePresentation.TitleMaster.HeadersFooters.Clear
ActivePresentation.TitleMaster.HeadersFooters.SlideNumber.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Clear
ActivePresentation.HandoutMaster.HeadersFooters.DateAndTime.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Header.Visible = msoFalse
ActivePresentation.PrintOptions.PrintColorType = ppPrintPureBlackAndWhite
ActivePresentation.PrintOptions.OutputType = ppPrintOutputThreeSlideHandouts
ActivePresentation.PrintOptions.FrameSlides = msoCTrue
End Sub
Cosmo
12-15-2009, 11:52 AM
Hi guys,
I am just dabbling in VBA. Here is my situation: I am given a large number of powerpoint files, some of which have dates/page numbers/titles in the headers and footers and some of which don't. I want to strip all headers and footers and print 3 per page handouts, with outlines. I have figured out how to set the print options to print 3 per page and outlines, but I can't seem to get rid of page numbers, dates, and titles. Can you help?
Here's the code I have so far:
Sub print3slides()
ActivePresentation.TitleMaster.HeadersFooters.Clear
ActivePresentation.TitleMaster.HeadersFooters.SlideNumber.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Clear
ActivePresentation.HandoutMaster.HeadersFooters.DateAndTime.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Header.Visible = msoFalse
ActivePresentation.PrintOptions.PrintColorType = ppPrintPureBlackAndWhite
ActivePresentation.PrintOptions.OutputType = ppPrintOutputThreeSlideHandouts
ActivePresentation.PrintOptions.FrameSlides = msoCTrue
End Sub
You need to loop through all of the slides. Add this to your code:
Dim oSld As Slide
For Each oSld In ActivePresentation.Slides
oSld.HeadersFooters.Clear
Next oSld
petersoni
12-15-2009, 12:37 PM
Cosmo...thanks for the response. That does not get rid of the page numbers or dates in my file.
Here is the code I have now:
Can anyone help get rid of the date and page numbers?
Sub test()
Dim oSld As Slide
For Each oSld In ActivePresentation.Slides
oSld.HeadersFooters.Clear
Next oSld
ActivePresentation.TitleMaster.HeadersFooters.Clear
ActivePresentation.TitleMaster.HeadersFooters.SlideNumber.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Clear
ActivePresentation.HandoutMaster.HeadersFooters.DateAndTime.Visible = msoFalse
ActivePresentation.HandoutMaster.HeadersFooters.Header.Visible = msoFalse
ActivePresentation.PrintOptions.PrintColorType = ppPrintPureBlackAndWhite
ActivePresentation.PrintOptions.OutputType = ppPrintOutputThreeSlideHandouts
ActivePresentation.PrintOptions.FrameSlides = msoCTrue
End Sub
Paul_Hossler
12-15-2009, 04:24 PM
What version of PP?
Paul
petersoni
12-15-2009, 05:33 PM
2007
Paul_Hossler
12-16-2009, 08:07 AM
Give this a shot
Sub DeleteDateFooterNumber()
Dim oPres As Presentation
Dim oSlide As Slide
Dim oShape As Shape
Dim i As Long
Set oPres = ActivePresentation
For Each oSlide In oPres.Slides
For i = oSlide.Shapes.Count To 1 Step -1
With oSlide.Shapes(i)
If .Type = msoPlaceholder Then
Select Case .PlaceholderFormat.Type
Case ppPlaceholderDate, ppPlaceholderFooter, ppPlaceholderSlideNumber
.Delete
End Select
End If
End With
Next
Next
End Sub
Paul
petersoni
12-16-2009, 08:14 AM
Nope, doesn't work. But thanks for the try!
Cosmo
12-16-2009, 08:33 AM
Try changing the code I sent toDim oSld As Slide
For Each oSld In ActivePresentation.Slides
oSld.HeadersFooters.Clear
oSld.HeadersFooters.SlideNumber.Visible = msoFalse
oSld.HeadersFooters.DateAndTime.Visible = msoFalse
Next oSld
It's possible that the slide numbers were added as a separate text box, instead of using the program's slide number field (which may very well be true if Paul's code didn't work). If this is the case, then there probably is no way to tell them apart from any other textbox.
...although you could try comparing the content of the textbox to the slide number.
Dim oSlide As Slide
Dim oPres As Presentation
Dim i As Integer
Set oPres = ActivePresentation
For Each oSlide In oPres.Slides
For i = oSlide.Shapes.Count To 1 Step -1
With oSlide.Shapes(i)
If .HasTextFrame Then
If IsNumeric(.TextFrame.TextRange.Text) Then
If CInt(.TextFrame.TextRange.Text) = CInt(oSlide.SlideNumber) Then
.Delete
End If
End If
End If
End With
Next
Next
NOTE - This WILL delete ANY text box whose entire contents is the same as the slide number, so make sure you don't have any other text boxes whose contentx may happen to be the slide number. If you decide to give this a try, do so only on a duplicate of the presentation, and check carefully to be sure it didn't delete anything it wasn't supposed to.
John Wilson
12-16-2009, 08:57 AM
Does this not work??
Sub zapper()
Dim osld As Slide
For Each osld In ActivePresentation.Slides
With osld.HeadersFooters
.DateAndTime.Visible = False
.Footer.Visible = False
.SlideNumber.Visible = False
End With
Next osld
End Sub
Paul_Hossler
12-16-2009, 10:02 AM
Seems to work in my 2007 - what happens? Can you post a sample where it failed?
Possibly the footers or date or slide numbers are regular text boxes, and not the special PlaceHolder type of shapes
Paul
John Wilson
12-17-2009, 04:28 AM
I should have said Paul's code worked for me too.
smithpick
03-31-2010, 03:29 AM
这是新加的空白文章5,可以在UBB可视化编辑器中,添加和修改文章内容。
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.