Code to execute when Addin is unloaded, not closed (powerpoint)

B

bourgui

Hi All,

I have this addin for Powerpoint for which I created a toolbar.

The toolbar is added when the addin is loaded, via the 'Auto_Open'
method, and removed when the addin is unloaded with 'Auto_Close'.

It works fine, except that the 'Auto_Close' method is also run
whenever powerpoint is closed, which removes the toolbar. When
powerpoint is started again, the toolbar is recreated, which
unfortunately repositions the toolbar at the end of all the existing
toolbars, regardless of whether the client had moved the toolbar or
not.

So I was thinking, is there a way that I can determine whether the
'Auto_Close' method is being called because Powerpoint is closing or
because the addin is being unloaded. I can't change the OnClose event
itself, as it is installed on clients' machines

If my guess is correct, if the toolbar is not removed, it should
appear in the same position after a restart. Or am I wrong?

Or is there a different way of doing this?

thanks!
 
M

Mike Clayton

bourgui,

I don't think there's a way of determining Application closing from AddIn
unloading - Auto_Close is all you get to work with. I tried to solve this
myself a while ago, but I couldn't find a "clean" solution.

In the end I just recreated the Commandbar in Auto_Open each time, and
destroyed it in Auto_Close, but I also added a bit of simple code to write
some of the CommandBar position properties to the registry (rowindex,
position, top, left, width, height, type) before it deleted the CommandBar,
and then it restores them again in Auto_Open. It's not perfect, but it works
most of the time.

It obviously loses and button customisations the user made during a session,
but in my case that's a desired behaviour. Someone else might have a better
solution for you though...

Mike
 
S

Steve Rindsberg

If my guess is correct, if the toolbar is not removed, it should
appear in the same position after a restart. Or am I wrong?

That's correct. PowerPoint maintains toolbar customizations made by code in
the same way as it does the user's manual customizations.

Other than resorting to installer/uninstallers to remove toolbars, you really
have two choices:

Re-create the toolbar at each startup (meaning you're going to mess up any user
customizations re your toolbar, so you'll annoy at least *some* users every
time PPT starts up, or

Let don't remove the toolbar. Your startup code checks for it and if it's not
there creates it. Then, worst case, a user who uninstalls your add-in will
have to use View, Toolbars, Customize to delete the now-dead toolbar.
 
J

jaf

Hi,
Not familiar with power point. I'm assuming your toolbar has a name.

When your auto_open runs check to see if the named toolbar is already open.
Exit the sub if it is.

There is a before_close event in most VBA libs. You should be able to detect
a close event and query whether your addin called it or the power point
application obj.
(if there is an application object in power point)

John
 
B

bourgui

Thank you Steve and Mike,

I think I will go with the registry approach, good idea.

Cheers!
 
S

Steve Rindsberg

There is a before_close event in most VBA libs. You should be able to detect
a close event and query whether your addin called it or the power point
application obj.
(if there is an application object in power point)

There's an application object in PowerPoint, but it doesn't expose a
Before_Close event. If I recall correctly, the app unloads all addins prior to
closing anyhow, so the add-in wouldn't be able to tell why it's closing that
way, I don't think.

But if you have a working example for, say, Excel or Word, I'd like to see it.
If I can work out how to adapt it to PPT, I'll post back.

That does suggest another idea, though.

The add-in's Auto_Close sub could enumerate visible windows and if it finds the
one titled "Add-Ins", it's a fair bet that the user's unloaded the add-in
deliberately (and so the toolbar should be deleted). Otherwise, leave it.
 
B

bourgui

The add-in's Auto_Close sub could enumerate visible windows and if it finds the
one titled "Add-Ins", it's a fair bet that the user's unloaded the add-in
deliberately (and so the toolbar should be deleted).  Otherwise, leave it.


Hmm, that gives me a few ideas. I'll try a few and post them back if I
find anything interesting.
Thanks all!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top