How to simulate ThisPresentation in PowerPoint VBA

Like everyone else I expected a ThisPresentation object in PowerPoint. I thought of another way to accomplish it, without a hardcoded filename. Obviously any piece of code would need to know how to distinguish between the projects. I chose to use the projectname for this (default name "VBAProject" in the Project Explorer): it is not used for anything else, no user will change it and if it is protected they can't.

Here is my code (change MyProject into your own projectname):

Function ThisPresentation() As Presentation
Dim p As Presentation

For Each p In Presentations
    If p.VBProject.Name = "MyProject" Then
        Set ThisPresentation = p
        Exit Function
    End If
Next
End Function

Tags:

Vba

Powerpoint