Search code examples
vbapowerpoint

How to simulate ThisPresentation in PowerPoint VBA


I would like to be able to access the document properties of a PowerPoint add-in file (a presentation saved as "PowerPoint Add-in (*.ppa)", from some VBA code in the add-in itself.

If it helps to understand the problem, what I'm actually trying to do is read a custom document property that stores the version number of the add-in, so that I can display that in a dialog box.

With Word & Excel I can do this using ThisDocument & ThisWorkbook, both of which return a reference to the document containing the running code. However, there is no ThisPresentation equivalent in PowerPoint.

For a standard PowerPoint presentation or template, I could use ActivePresentation. However, this method won't work for an add-in.

Any ideas? Please, no suggestions about where else I should stick the version number :-)


Solution

  • REVISED FEB 2, 2010: Cleaned up answer to only show the final solution


    Here's the way to do what was asked, no DLLs. Really simple:

    Sub ReturnPPAasPresentation()
        Dim p As Presentation
        Set p = Presentations("presentation1.ppa")
        Dim title As String, version As String
        version = p.CustomDocumentProperties("Version").Value
        title = p.BuiltInDocumentProperties("Title").Value
        MsgBox "Version: " & version & " of " & title, vbOKOnly, title
    End Sub