INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

powerpoint vba to remove header footer, page numbers and date

powerpoint vba to remove header footer, page numbers and date

(OP)
I found code to hide the page numbers and date from powerpoint 2013, which I assumed would have the same effect as clickihttp://www.tek-tips.com/threadminder.cfm?pid=707ng on View, Handout Master and unticking Date and Page Number in the Placeholders section and then print the result to pdf with two slides per page without saving the pptx file. I tried two versions of the code, commented out and uncommented and the only part that works is saving the file to pdf. There are no error messages or code stoppage. Unfortunately, when I open the pdf, the headers and footers are still there for the date and page number. (I also originally tried the code within powerpoint's vba module rather than through automation and it didn't work there either)

CODE -->

Private Sub btnPPT2PDF_Click()
'zapper()
'http://www.vbaexpress.com/forum/showthread.php?29698-Simple-Powerpoint-Macro-Remove-Page-Numbers-Footers-Etc
'post 9
'http://peltiertech.com/Excel/XL_PPT.html
'20170413
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim stFileName As String

    ' Reference instance of PowerPoint
    On Error Resume Next
    ' Check whether PowerPoint is running
    Set PPApp = GetObject(, "PowerPoint.Application")
    If PPApp Is Nothing Then
        ' PowerPoint is not running, create new instance
        Set PPApp = CreateObject("PowerPoint.Application")
        ' For automation to work, PowerPoint must be visible
        PPApp.Visible = True
    End If
    On Error GoTo 0
        
    stFileName = "c:\temp\MyPowerPointFile.pptx" 
    
    PPApp.Presentations.Open (stFileName)
    
    Set PPPres = PPApp.ActivePresentation
    Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
    
    'http://bettersolutions.com/powerpoint/PZZ583/VI114366552.htm
    With PPPres.SlideMaster.HeadersFooters
        .DateAndTime.Visible = msoFalse
        .Footer.Visible = msoFalse
        .SlideNumber.Visible = msoFalse
    End With
    'For Each PPSlide In PPApp.ActivePresentation.Slides
    '    With PPSlide.HeadersFooters
    '        .DateAndTime.Visible = msoFalse
    '        .Footer.Visible = msoFalse
    '        .SlideNumber.Visible = msoFalse
    '    End With
    'Next PPSlide
    'https://msdn.microsoft.com/en-us/library/office/ff746080.aspx
    PPApp.ActivePresentation.ExportAsFixedFormat "C:\temp\PPT2PDF.pdf", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputTwoSlideHandouts, msoFalse, , , , False, False, False, False, False
    
Error_Handler_Exit:
    On Error Resume Next
    PPApp.Quit
    Set PPTslide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing
    Exit Sub
 
Error_Handler:
    MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: OpenPPT" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit

End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close