PowerPoint VBA - Preserving Custom CommandBar Settings on Close
-
28-09-2019 - |
Question
I have developed a PowerPoint add-in for versions 2003 and earlier that generates a custom commandbar/toolbar on install.
I have no difficulty removing this commandbar on uninstall, but because it uses the Auto_Close
event to do so, it also deletes the toolbar every time PowerPoint closes, preventing the user from permanently customizing the commandbar's position.
I've tried a conditional delete by checking if the add-in is registered or loaded, but Auto_Close
seems to run before any unloading or deregistration.
Any ideas on how to delete the commandbar ONLY when the add-in is being uninstalled?
Sub Auto_Close()
Dim pptAddin As AddIn
For Each pptAddin In AddIns
If pptAddin.Name = "AddInName" And _
pptAddin.Registered <> msoTrue Then
Application.CommandBars("CommandBarName").Delete
End If
Next
End Sub
Solution
It's a good idea to do what you're doing - deleting your CommandBar when PowerPoint closes. That way if there is ever an error, your add-in doesn't leave artifacts in the UI that don't work.
For managing state though, many folks use GetSetting
and SaveSetting
for reading/writing to a sandboxed area in the Registry for VB/VBA programs. Look up the following functions on this page: GetSetting
, SaveSetting
, GetAllSettings
, DeleteSetting
. You can use these to manage your add-in's CommandBar between PowerPoint instances. It's relatively simple to use - here's a tutorial for Excel that would apply equally to PowerPoint.