Multiple Toolbars being added/Multiple Buttons being added to Mail

M

Matt

Hello,

I am developing an outlook add-in which requires a single toolbar with a
single button being added to the MailEditor window. Upon debugging my project
the first time, the button is created and all is well. However, after closing
outlook and debugging again, a duplicate toolbar is added (with the button).
This continues to happen and toolbar after toolbar is added. I manually
remove the Add-In and restart Outlook and the buttons are still there, the
only way to remove them is by restarting my PC, and it just happens again.
How would I go about solving this problem?

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Always make sure to set the UI you create as temporary, and then delete it
before the relevant Explorer or Inspector closes.
 
K

Ken Slovak - [MVP - Outlook]

The CommandBars.Add() method has a temporary argument, set it to True if you
create a new CommandBar object. The CommandBarControls.Add() method also has
that argument available when you add a new control to a CommandBar
(menu/toolbar). Also set that True.

That's generally enough, but if for some reason Outlook doesn't correctly
close or crashes a belt plus suspenders approach is to handle the
Inspector.Close() event on any Inspector you are adding UI to, and the
Explorer.Close() event on any Explorer you add UI to. In those event
handlers you get your references to the controls and commandbars you added
and call their Delete() method to delete them.

There's lots of sample code in various languages at www.outlookcode.com that
shows handling those Close() events and how to handle adding and removing
UI. Take a look there for samples in your language.
 
M

Matt

My commandbar was set as temporary but the button was not. Is this way correct:

button_1 = CType(newToolBar.Controls.Add(1, 1, Nothing, Nothing, True),
Office.CommandBarButton)

?
 
K

Ken Slovak - [MVP - Outlook]

For optional missing values use System.Reflection.Missing.Value instead of
using Nothing. I usually define a class or global _missing variable object
for that.

In general, unless you are using a built-in control it's usually better to
not specify the ID argument and to supply the missing value for that also.
So I'd code that as:

button_1 = CType(newToolBar.Controls.Add(1, _missing, _missing, _missing,
True),
Office.CommandBarButton)

Also, when you set the other properties of any button you create make sure
to always use a unique Tag property. That prevents the button Click() event
from firing as many times as you have open items (Inspectors) or open folder
views (Explorers). With a unique Tag the Click() will fire only in that one
Inspector or Explorer.
 

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