Command bar controls not being removed from Word

Add-in Express™ Support Service
That's what is more important than anything else

Command bar controls not being removed from Word
If I exit Word, my addin's menu controls are not removed 
Steve Weixel


Guest


If I exit Word while my addin is running, my addin's controls are not removed and the next time I start Word the controls are still there on the menu bar. If I "disconnect" my addin first, before exiting Word, the controls *ARE* removed. I've tried setting the temporary state to true and false but it doesn't make any difference. I am creating my menu at runtime, from AddinInitialize:

Dim CommandBar As New AddinExpress.MSO.ADXCommandBar(Me.GetContainer)
CommandBar.CommandBarName = "Menu Bar"

'Create a new popup for our menu.
Dim CommandBarPopup As New AddinExpress.MSO.ADXCommandBarPopup(Me.GetContainer)
CommandBarPopup.BeforeID = 30008
CommandBarPopup.Caption = "My Addin Menu"
CommandBar.Controls.Add(CommandBarPopup)
Return CommandBarPopup

Is there some kind of event that ADX is handling when it gets disconnected that doesn't fire when Word exits directly? I've tried manually? I know that AddinBeginShutdown is being called so it seems that it gets something. I've also tried manually removing my menu but it doesn't go away. I do the same thing in Excel and it works fine.

Thanks,
Steve
Posted 17 Jun, 2005 12:58:37 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Steve.

Probably you have ever had your command bars are not temporary and Word has saved their to the Normal.dot template. In this case it is not enough to remove command bars manually in Word using the Customize dialog or the code in your add-in. You should remove command bars via the Organizer dialog as well. Just open the Tools->Templates and Add-ins dialog and click the Organizer button. Then choose the Toolbars tab and delete your command bar from the Normal.dot template (if it exists there).
Then open your add-in solution and set the Temporary property of all command bars to true and build the solution. Now all should work. If no, please send me the code. I will try to help.

Posted 17 Jun, 2005 15:56:54 Top
Steve Weixel


Guest


As I said before, setting it to temporary doesn't make any difference.

Here is all of the relevant code (I removed some parts that didn't matter):

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' NAME: CreatePostMenuStub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function CreatePostMenuStub(ByVal commandBarName As String, ByVal beforeId As Integer) As AddinExpress.MSO.ADXCommandBarPopup
Dim CommandBar As New AddinExpress.MSO.ADXCommandBar(Me.GetContainer)
CommandBar.CommandBarName = commandBarName
CommandBar.Temporary = True

'Create a new popup for the ACEIT menu.
Dim CommandBarPopup As New AddinExpress.MSO.ADXCommandBarPopup(Me.GetContainer)
CommandBarPopup.Temporary = True
CommandBarPopup.BeforeID = beforeId
CommandBarPopup.Caption = "&POST"
CommandBar.Controls.Add(CommandBarPopup)
Return CommandBarPopup
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' NAME: CreateMenuButton
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Overloads Function CreateMenuButton(ByVal controls As AddinExpress.MSO.ADXCommandBarPopupControlCollection, ByVal caption As String, ByVal action As String, Optional ByVal beginGroup As Boolean = False, Optional ByVal faceId As Integer = 0, Optional ByVal disabled As Boolean = False) As AddinExpress.MSO.ADXCommandBarButton
Dim MenuButton As New AddinExpress.MSO.ADXCommandBarButton(Me.GetContainer)
MenuButton.Temporary = True
MenuButton.Caption = caption
MenuButton.Style = AddinExpress.MSO.ADXMsoButtonStyle.adxMsoButtonIconAndCaption
MenuButton.FaceID = faceId
MenuButton.BeginGroup = beginGroup
MenuButton.Enabled = Not disabled
controls.Add(MenuButton)
AddHandler MenuButton.Click, AddressOf OnCommandBarButtonClick
Return MenuButton
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' NAME: CreateMenuPopup
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Overloads Function CreateMenuPopup(ByVal controls As AddinExpress.MSO.ADXCommandBarPopupControlCollection, ByVal caption As String, Optional ByVal beginGroup As Boolean = False) As AddinExpress.MSO.ADXCommandBarPopup
Dim MenuPopup As New AddinExpress.MSO.ADXCommandBarPopup(Me.GetContainer)
MenuPopup.Temporary = True
MenuPopup.Caption = caption
MenuPopup.BeginGroup = beginGroup
MenuPopup.Enabled = True
controls.Add(MenuPopup)
Return MenuPopup
End Function

and in AddinInitialize:

'Create the menu stubs. In some hosts there may be more than one.
If Me.HostType = AddinExpress.MSO.ADXOfficeHostApp.ohaExcel Then
mPostMenuStubs = New AddinExpress.MSO.ADXCommandBarPopup() {Me.CreatePostMenuStub("Worksheet Menu Bar", 30011), Me.CreatePostMenuStub("Chart Menu Bar", 30022)}
ElseIf Me.HostType = AddinExpress.MSO.ADXOfficeHostApp.ohaWord Then
mPostMenuStubs = New AddinExpress.MSO.ADXCommandBarPopup() {Me.CreatePostMenuStub("Menu Bar", 30008)}
End If

For Each PostMenuStub As AddinExpress.MSO.ADXCommandBarPopup In mPostMenuStubs
With PostMenuStub
Me.CreateMenuButton(.Controls, "&Open Session(s)...", "OpenSession")
End With
Next PostMenuStub

Posted 17 Jun, 2005 20:01:35 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Steve.

The fact is that, Word automatically saves your controls in the Normal.dot template when you add controls to the built-in menu. You should check if your controls exist in Word then connect to them. Otherwise you can create new controls. I can send you an example illustrating how to implement this option in your add-in.

One more think. Probably you noticed that we added a new method to the ADXAddinModule component called CommandBarAdd. This method allows you to add command bars to Office applications at runtime regardless of whether they already exist or not.
Posted 19 Jun, 2005 04:37:02 Top
Steve Weixel


Guest


Hi Sergey,

Everything works fine when the addin is reloaded, it replaces the previous menu with the new one. The problem is when Word is started again without the addin; the controls are left there from the previous time. Since our addin is not running at that point there is nothing that we can do to remove them. I am trying to find a way that our addin can remove the controls that we added when the addin is *shutting down*.

This happens for us automatically if the user goes to the COM add-ins dialog and unchecks the addin. The addin disconnects and our menu goes away. But unfortunately it does not happen if the user closes Word outright. I am just trying to figure out the appropriate way to remove my menu. When the user unchecks the addin and it disconnects, is it ADX that is removing the menu at that point or is Word doing it?

Steve
Posted 20 Jun, 2005 13:49:02 Top
Steve Weixel


Guest


Update: Apparently when setting the commandbar and its controls to temporary, the menu no longer updates itself automatically when the addin is restarted and I do end up with multiple copies of my menu. I tried CommandBarAdd (sorry I didn't have a chance to try it sooner after you sent it to me) but it didn't help, the behavior was the same. I seem to recall a while ago reading another forum post where someone else was complaining that the word menus were not removed if temporary=true. I tried removing the menu manually again directly through Word in AddinBeginShutdown but all I get is an error from Word.

For Each PostMenuStub As AddinExpress.MSO.ADXCommandBarPopup In Me.mPostMenuStubs
If TypeOf PostMenuStub.ControlObj Is Microsoft.Office.Core.CommandBarPopup Then
Dim Popup As Microsoft.Office.Core.CommandBarPopup = DirectCast(PostMenuStub.ControlObj, Microsoft.Office.Core.CommandBarPopup)
Popup.Delete((False))
End If
Next PostMenuStub
Posted 20 Jun, 2005 14:44:47 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Steve.

is it ADX that is removing the menu at that point or is Word doing it?

Yes. ADX removes its contols automatically when the user disconnects an add-in.

I am trying to find a way that our addin can remove the controls that we added when the addin is *shutting down*.

I have just sent you an example by email. Please check your inbox.
Posted 20 Jun, 2005 15:09:55 Top