In an addin template in Word 2002, I've written code (Sub BuildUI) to create a couple of custom menus and a custom toolbar with a couple of buttons. I've also written the code to delete the menus and toolbar (Sub DeleteUI). The menus, commands, and toolbar buttons are deleted with the code snippet below; the toolbar by name. (This method ensures that the controls are also deleted if the user has moved them.)
The BuildUI procedure is called from AutoExec; DeleteUI from AutoExit. DeleteUI is also called at the start of BuildUI to ensure that the custom UI is absent before it is created. I've verified through MsgBoxes that the code does run.
This method has always worked for any solution I've created. But in the environment I'm working in now, things are odd.
When I launch Word with the addin installed, Word appears with multiple copies of the toolbar. These are immediately deleted, and the custom UI recreated, but next time I launch Word, yet another copy of the toolbar is present before they are all deleted again. And so on; every time I launch Word, one more copy of the toolbar is present before it's deleted by my code.
I have verified that the toolbar(s) is/are not embedded in Normal, nor are they present in my addin. I have also verified that the CustomizationContext for my code is Normal.
Obviously, I don't want this growing number of toolbars when my users launch Word. Even though they are immediately deleted, it looks sloppy, and I'm concerned that there will come a point when Word can no longer handle this multitude of identical toolbars.
Dim ctls As Controls, ctl As Control
Set ctls = Application.CommandBars.FindControls(Tag:=MyTag)
'Controls get MyTag as tag on creation
If Not ctls Is Nothing Then 'FindControls returns Nothing if no controls with that tag
For Each ctl In ctls