Deleting Word menus

Hi,
I'm working on a Word2003 addin that adds some menus. When I uninstall the addin, the menus are still visible but are inactive. To delete them, I must delete the Normal.dot file. Is there a better way to do this, because I can't delete the user's Normal.dot file ?
Thank you
[295 byte] By [Gastiflex] at [2008-1-10]
# 1

Hi,

You can right click the area of tool bar, and click Customize button. When the Customize Dialog appears on the top of Word, you can drag the button out of tool bar. If you want to remove the custom tool bar, you can navigate to the Toolbars tab in the dialog and select your custom tool bar and click the Delete button.

Hope it helps.

Thanks

Ji

JiZhou–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 2
Hi,
thank you but actually, we are selling this addin to our customers. So when they uninstall our product, we must delete our menus in Word. We can't tell them "go in Tools-> Customize..." (or "delete the Normal.dot file", like we did until now when they were calling the hotline ).
That's why I was looking for a way to delete them automatically.
Gastiflex at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 3

Hi,

How did you add the Command bar button? If you specific the temporary parameter to true and set the button’s Tag, every time you close the Word, the button will be removed, and will be created again when the Add In is loaded next time. So in this case, after your customer uninstalls the Add In, your button will not be created again. My code is as follows:

Code Snippet

private Office.CommandBar cb = null;

private Office.CommandBarButton btn = null;

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

cb = this.Application.CommandBars.Add("test", Office.MsoBarPosition.msoBarTop, false, true);

cb.Visible = true;

btn = cb.Controls.Add(Office.MsoControlType.msoControlButton,

missing, missing, missing, true) as Office.CommandBarButton; //The last parameter should be true

btn.Tag = "BTN_TAG";//Set the Tag

btn.Caption = "Button";

btn.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;

btn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btn_Click);

}

Thanks

Ji
JiZhou–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 4
Hi, here's my function that add menus :
Code Block

Private Sub AddMenu(ByRef cmdBarControl As Office.CommandBarPopup, ByVal menuCaption As String)
Dim menuBar As Office.CommandBar = Application.CommandBars.ActiveMenuBar

If menuBar IsNot Nothing Then
cmdBarControl = Nothing
Dim controlCount As Integer = menuBar.Controls.Count

' Add the new menu.
cmdBarControl = CType(menuBar.Controls.Add( _
Type:=Office.MsoControlType.msoControlPopup, Before:=controlCount, Temporary:=True), _
Office.CommandBarPopup)

cmdBarControl.Caption = menuCaption
cmdBarControl.Tag = menuCaption

End If
End Sub

And the one that add buttons :
Code Block

Private Sub AddCommandToMenu(ByVal strMenuName As String, ByRef command As Office.CommandBarButton, ByVal strCommandName As String, ByVal pos As Integer, Optional ByVal strPictureName As String = "", Optional ByVal strMaskName As String = "", Optional ByVal iPictureId As Integer = 0)
Dim menu As Office.CommandBarPopup

menu = app.CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, , strMenuName)
command = menu.CommandBar.FindControl(Office.MsoControlType.msoControlButton, , strCommandName)

If (command IsNot Nothing) Then
command.Delete()
End If
command = menu.Controls.Add(Office.MsoControlType.msoControlButton, , "", pos, True)
command.Caption = strCommandName
command.Tag = strCommandName

If (Not (String.IsNullOrEmpty(strPictureName))) Then
command.Picture = GetImage(strPictureName)
If (Not (String.IsNullOrEmpty(strMaskName))) Then
command.Mask = GetImage(strMaskName)
End If
ElseIf (iPictureId <> 0) Then
command.BuiltInFace = True
command.FaceId = iPictureId
End If
End Sub


I think they do the same thing than yours.
But maybe it's just a kind of "refresh problem" : when I uninstall the addin, the menus are still visible but they're inactive.
Gastiflex at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 5

Hi,

Yes. I agree that our codes should perform the same. The code looks all right. Then maybe we have to use the custom action to remove the buttons. (Get the button’s handle to remove it or delete the Normal.dot).You can get more information about the custom action in the following link:

http://msdn2.microsoft.com/en-us/library/d9k65z2d(VS.80).aspx

Thanks

Ji

JiZhou–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...