views:

530

answers:

1

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 :-)

+1  A: 

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
Otaku
Thanks for your reply. Unfortunately, I don't think this does solve my particular problem. It covers various scenarios, but not one in which an **add-in** needs to get a reference to itself. Even using Addins(myName) would only give me a reference to an AddIn object, which doesn't let me get at the document properties, etc. of the add-in. Still, thanks for trying!
Gary McGill
The add-in *does* actually have document properties, in that you can still get and set the properties via Windows Explorer. But, I've come to the conclusion that it's simply not possible to access that through code (or at least not through the VBA object model). Thanks for trying, but I think it's time to give up.
Gary McGill
Erm, yes, I can define the constant in the code - and I could then report it using MsgBox rather more easily than creating a textbox :-) But, as I said in my question, I'm not really interested in doing it *in a different way* - I'm more interested in whether it's theoretically possible to access the doc props. (And I think I have my answer - it's not).
Gary McGill
Got it. I don't have the PPT doc properties exposed in Windows Explorer on my box - just the add-in properties (name, type, etc.) and any custom properties I want to set. This is consistent with COM Add-ins, of which a PPA is the same thing with just a different file extension. Does yours have the PPT document properties (i.e. BuiltInProperties) like "Title", "Subject", "Author", "Typist", etc. in Windows Explorer? If so, what versions of PPT and Windows are you using - it's just I've never heard of this before and I'm interested to know.
Otaku
Well, I stand corrected. It appears at least some of the original BuiltInDocumentProperties are retained in a PPA. I can't confirm if CustomDocumentProperties are as well.Here's a DLL that will allow you to read document properties. It *may* work for you. http://support.microsoft.com/kb/224351/en-us
Otaku
OK, after all that effort, I can't possibly *not* accept your answer :-) It's not a solution I would actually use in practice, because of the deployment issues (everyone needs to install DsoFile), but yes, it would work. Thanks for all your effort!
Gary McGill
Sure, understood about the deployment issues. The DSO source is in C++, but maybe it can be ported to VBA to reside within your PPA.
Otaku
Okay, it can be done, really simple. Just assume the PPA can be part of the presentations collection and you've got it. Final revision above!
Otaku