PDA

View Full Version : ThisPresentation for an Add-In file



Chris Macro
08-06-2014, 07:33 AM
I know that in PowerPoint VBA there is now such thing as ThisPresentation. I need to set a variable however the presentation the VBA code is stored to. I have been able to do this by using the file name, for example I could write:


Set ThisPresentation = Presentations("Custom Macros.pptm")

However if I try to do this with an add-in file it doesn't seem to work, for example I tried:


Set ThisPresentation = Presentations("Custom Macros.ppam")


Are there any other ways to set a variable to the add-in file in PowerPoint? I am trying to create a userform add-in that can variably updated listbox that eventually populates an Array. My problem is that I want the userform to remember the listbox items after PowerPoint is closed so next time you don't have to re-enter the items in the listbox. I was accomplishing this by having VBA rewrite its own code.

John Wilson
08-06-2014, 08:35 AM
You can store the values in a textfile or in registry keys (I would do this) which is saved and read when the list changes and when the AddIn loads. They cannot be stored within the ppam AFAIK

Look at SaveSetting and GetSetting

Chris Macro
08-06-2014, 08:52 AM
I thought about doing that (a registry key) but was hopeful that there might be an alternative solution. My biggest concern was when I shared the add-in that I wanted to have some default items pre-populated in the listbox. I suppose I could just make an IF statement to check and see if a specific registry was made or not. Thanks for your advice John!

John Wilson
08-06-2014, 09:16 AM
If you use getSetting Chris you can specify the default value if the reg key is absent.

Chris Macro
08-06-2014, 10:13 AM
Oh, didn't know that. Let me play around with it and I'll let you know if I run into problems.

John Wilson
08-07-2014, 04:00 AM
So for example

strInput1 = GetSetting("Chris", "Data", "Val1", "John")

Will set strInput1 to John if there is no key at

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Chris\Data\Val1

If the key exists strInput1 will be set to the value of that key