I have a PowerPoint presentation saved as .pptm
. I want the presentation to be automatically exported to PDF whenever I save it (that is, whenever I press CTRL+S
).
In the Visual Basic view, I have created a new module under VBAProject
:
VBAProject
|-- Modules
|-- Module1
In Module1
, I have added the following code:
Private Sub App_PresentationBeforeSave(ByVal Pres As Presentation, ByVal Cancel As Boolean)
' PDF Filename
Dim PDF_Filename As String
PDF_Filename = "C:/Users/user/directory/file.pdf"
'Export the presentation as PDF when saving
ActivePresentation.ExportAsFixedFormat PDF_Filename, ppFixedFormatTypePDF, ppFixedFormatIntentPrint ppFixedFormatTypePDF
End Sub
This is not working, as when I update the presentation (CTRL+S
), no PDF file is produced.
From experience working with VBA for Excel and Word, I have the suspicion that the code should be placed in ThisWorkbook
, however, there is no such construct or similarly named item in the VBA view, VBAProject
was empty when I accessed it.
How can I make this code work?
Your code relies on responding to an application event, but in order to make it fire, you must set up an event trap. Jamie Garroch has the best and most complete explanation of this I've seen here:
http://youpresent.co.uk/powerpoint-application-events-in-vba/