none
How to edit Normal.dotm file, and remove only Addins created button(Program Defined) using VB .Net RRS feed

  • Question

  • Type: critical issue

     

    Environment:

    OS : - Windows xp sp2/7

    IDE : - Visual Studio 2008

    Word: MS Office 2007, MS Office 2010

    Language : - VB .net

    Project type : - File --> New Project --> Others Project Types -->Extensibility --> Shared Add-in

     

    Problem Description: We have Addins component which runs properly. When we install this component It create a button {SaveDocument}in word.

    But when we uninstall the Addins component , It doesn’t  remove "SaveDocument" button.

    Atempt: - According to findings, We found that button information store in AppData\Roaming\Microsoft\Templates\Normal.dotm. So, if some how, we can remove button information from Normal.dotm, then It can be removed easily, without deleting other setting in Normal.dotm

    Requirement: -

    I tried to search on internet for editing and remove that button information from Normal.dotm using vb.net. But, till now, I haven't found any helpful article.

    Kindly assist, I will be really thankful.


    Regards, S.P Singh


    • Edited by S.P Singh Monday, February 15, 2016 9:52 AM Question Editied
    Monday, February 15, 2016 9:47 AM

All replies

  • Hello Singh,

    You need to do the opposite operation when the add-in is uninstalled. For that you need to add a custom action to your installer and create an instance of the Word application programmatically where you can find and remove any custom controls.

    Be aware, command bars were deprecated and not used any longer. I'd recommend using the Fluent UI instead (Office 2007+). You can read more about that in the following series of articles:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    It doesn't require removing controls when the add-in is uninstalled.


    Monday, February 15, 2016 1:07 PM
  • You need to do the opposite operation when the add-in is uninstalled. For that you need to add a custom action to your installer and create an instance of the Word application programmatically where you can find and remove any custom controls.


    Kindly suggest some code snippet or help article for that.

    I will be really thankful.


    Regards, S.P Singh

    Tuesday, February 16, 2016 2:06 PM
  • What code do you use for adding custom controls?
    Tuesday, February 16, 2016 2:11 PM
  • Following is the code snippet:

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
    
            Dim oCommandBars As CommandBars
            Dim oStandardBar As CommandBar
    
            On Error Resume Next
            ' Set up a custom button on the "Standard" command bar.
            oCommandBars = applicationObject.CommandBars
            If oCommandBars Is Nothing Then
                ' Outlook has the CommandBars collection on the Explorer object.
                oCommandBars = applicationObject.ActiveExplorer.CommandBars
            End If
    
            oStandardBar = oCommandBars.Item("Standard")  
    
            ' In case the button was not deleted, use the exiting one.
            MyButton = oStandardBar.Controls.Item("SaveDocument")
            If MyButton Is Nothing Then
    
                MyButton = oStandardBar.Controls.Add(1)
                With MyButton
                    .Caption = "SaveDocument"
                    .Style = MsoButtonStyle.msoButtonCaption
                    .Tag = "SaveDocument"
                    .OnAction = "!<MyCOMAddin.Connect>"
    
                    .Visible = True
                End With
            End If
    
            ' Display a simple message to show which application you started in.
            'MsgBox("Started in " & applicationObject.Name & ".")
    
            oStandardBar = Nothing
            oCommandBars = Nothing
    
        End Sub


    Regards, S.P Singh

    Tuesday, February 16, 2016 2:22 PM
  • You can use the Delete method of the CommandBarButton class. It deletes the CommandBarButton object from its collection. For example:

    Sub delBar()
        CommandBars("MyToolbar").Controls(1).Delete
    End Sub
    

    Tuesday, February 16, 2016 8:50 PM
  • I have written following, but after un-installation of setup, button is showing in inactive mode. 

    After that I wrote a message box after delete syntax. On execution, I noticed that button got deleted, and after that message prompted. But, when I again relaunch word, it shows button in inactive mode. Kindly suggest

    Following is the snippet

    Dim WithEvents SaveDocumentButton As CommandBarButton
    
    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
    
            ' Notify the user you are shutting down, and delete the button.
            Dim oCommandBars As CommandBars
            Dim oStandardBar As CommandBar
            Try
    
                ' Set up a custom button on the "Standard" command bar.
                oCommandBars = applicationObject.CommandBars
                If oCommandBars Is Nothing Then
                    ' Outlook has the CommandBars collection on the Explorer object.
                    oCommandBars = applicationObject.ActiveExplorer.CommandBars
                End If
    
                oStandardBar = oCommandBars.Item("Standard")
                If oStandardBar Is Nothing Then
                    ' Access names its main toolbar Database.
                    oStandardBar = oCommandBars.Item("Database")
                End If
                MsgBox("Processing button deletion")
                SaveDocumentButton = oStandardBar.Controls.Item("SaveDocument")
                If Not SaveDocumentButton Is Nothing Then
                    SaveDocumentButton.Delete()
                    SaveDocumentButton = Nothing
                    MsgBox("Delete SaveDocumentButton")
                End If        
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            
    
        End Sub

    It seems to me that It got deleted programmatically, but its information is not deleting from Normal.dotm. And, that is the reason; it is showing in inactive mode(Only Showing not working).

    Kindly assist.


    Regards, S.P Singh



    • Edited by S.P Singh Wednesday, February 17, 2016 11:37 AM
    Wednesday, February 17, 2016 6:36 AM
  • Kindly assist.

    Regards, S.P Singh

    Thursday, February 18, 2016 5:28 AM
  • Hi S.P,

    As far as I know, CommandBars are removed from Office 2007. Could you share us a screen shot about your “SaveDocument” button? I made a test with your code under Word 2007, but I could not show any UI change in my Word. Could you share us a simple code or steps which could reproduce your issue?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, February 18, 2016 9:50 AM
  • Kindly suggest; I will be really thankful.

    ------------------------------------------------------

    I have created a sample project, which will describe to you, about the issue.

    This project create a setup in parallel, once you will install, it will create a button “SaveDocument”. You can click on it; I have written a snippet for it.

    And on closing of word, it will delete the button that code also has written. But that is in the code, so when we will uninstall setup then button remains as “SaveDocument” in inactive mode.

    Kindly find the attachment: -

    http://1drv.ms/1Qo9p1j



    Regards, S.P Singh




    Regards, S.P Singh

    Saturday, February 20, 2016 5:39 AM
  • 1) - Close all the MS Office Application

    2) - Install from shared project SaveDocumentSetup\Release\SaveDocumentSetup.msi

    3)- It will create a button "SaveDocument", on standard tool bar

    4) - Open the Word and click on button, It will show following

    5) - On Closing word, button will delete and following message will prompt

    6) - Uninstall the word, now you will get inactive button in word, while application has uninstalled. But, if you will delete Normal.dotm, it will delete the button.


    Regards, S.P Singh

    Tuesday, February 23, 2016 8:53 AM
  • 1) - Close all the MS Office Application

    2) - Install from shared project SaveDocumentSetup\Release\SaveDocumentSetup.msi

    3)- It will create a button "SaveDocument", on standard tool bar

    4) - Open the Word and click on button, It will show following

    5) - On Closing word, button will delete and following message will prompt

    6) - Uninstall the word, now you will get inactive button in word, while application has uninstalled. But, if you will delete Normal.dotm, it will delete the button.


    Regards, S.P Singh



    Regards, S.P Singh

    Friday, February 26, 2016 4:27 AM
  • Hi S.P,

    >> Uninstall the word, now you will get inactive button in word, while application has uninstalled. But, if you will delete Normal.dotm, it will delete the button.

    Do you have any other custom information in Normal.dotm? If not, I will suggest you delete it directly. If Normal.dotm is renamed, damaged, or moved, Word automatically creates a new version (which uses the original default settings) the next time that you start Word. The new version will not include any of the customizations that you made to the version that you renamed or moved.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, February 29, 2016 8:43 AM
  •             "Do you have any other custom information in Normal.dotm? If not, I will suggest you delete it directly. If Normal.dotm is renamed, damaged, or moved, Word automatically creates a new version (which uses the original default settings) the next time that you start Word. The new version will not include any of the customizations that you made to the version that you renamed or moved."

     

    Hi Sir, Application has to deploy on client machine; they may have their customization, so we cannot delete or rename the file.

    Kindly let me know, some other alternative. Is it possible to delete particular customization from Normal.dotm file from VB. Net?

     

    Kindly suggest, I will be really thankful.


    Regards, S.P Singh


    • Edited by S.P Singh Tuesday, March 1, 2016 3:00 PM File can not be delete, but it got mention can delete.
    Tuesday, March 1, 2016 1:57 AM
  • Hi S.P,

    Since you can delete the file, I suggest you use the code below:

            My.Computer.FileSystem.DeleteFile("C:\Users\Administrator\AppData\Roaming\Microsoft\Templates\Normal.dotm")

    Since command bars were deprecated and not used any longer, I suggest refer the link from Eugene to use Office Fluent Ribbon.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 1, 2016 6:33 AM
  • It cannot be deleted, somehow I wrote that It can be deleted while It cannot be, because

    Client may have their customization, so we cannot delete or rename the file.

    Can I change code in my VB.Net program from "Office Fluent Ribbon", and it will give same result?

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)



    Regards, S.P Singh


    • Edited by S.P Singh Tuesday, March 1, 2016 3:12 PM
    Tuesday, March 1, 2016 3:04 PM
  • Hi S.P,

    Code for Office fluent Ribbon is different from your original code for command bars, but if you use Office fluent Ribbon, you could get the same ribbon and button like what you have. And after you uninstall you vsto project, the ribbon would be removed.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, March 2, 2016 3:28 AM
  • Hi Edward,

       Does "Office Fluent Ribbon", support 2007, 2010 and onward version? And for development of it, what will be its pre-requisite.

    If possible, kindly provide any sample code in VB. Net. It would give better understanding. 


    Regards, S.P Singh

    Wednesday, March 2, 2016 3:44 AM
  • Hi S.P,

    Office Fluent Ribbon support Office 2007 and later version. There is no other requirements for using it.

    For samples about Office Fluent Ribbon, you could refer above reply.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 8, 2016 9:09 AM
  • Thanks Sir for details. But let me know that do we have any way to modify Normal.dotm using VB .Net language?

    Regards, S.P Singh


    • Edited by S.P Singh Wednesday, March 9, 2016 4:24 PM
    Wednesday, March 9, 2016 4:23 PM
  • Thanks Sir for details. But let me know that do we have any way to modify Normal.dotm using VB .Net language?

    Regards, S.P Singh




    Regards, S.P Singh

    Wednesday, March 16, 2016 5:39 PM
  • Hi S.P,

    >> But let me know that do we have any way to modify Normal.dotm using VB .Net language?

    Yes, we could use OpenXML SDK to modify Normal.dotm.

    You do as below:
    1. Prepare two documents, one has commandbar and another does not have, for the one which did not have, you could modify name of your original normal.dotm and then word will generate a new normal.dotm ;
    2. Use Open XML SDK 2.5 productivity Tool for Microsoft Office
    3. Click the Compare Files, generate the code, and then you could get the code what you want

    For more information about Open XML SDK 2.5 productivity Tool for Microsoft Office, you could refer the link below:

    # Open XML SDK 2.5 for Microsoft Office
    https://www.microsoft.com/en-us/download/details.aspx?id=30425

    Best Regards,

    Edward

     

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 17, 2016 5:57 AM
  • I have compared both file, one which is having button "SaveDocument" in standard tool bar and another which is not having any button. Following is the screen shot

    And, following code snippet was showing, when I clicked on /word/customizations.xml

    I am not able to understand this file. Kindly suggest, If I can remove particular button code.


    Regards, S.P Singh

    Monday, March 28, 2016 4:04 AM
  • Hi S.P,

    In your first image, click View Package Code, and you could create a class to use the generated code.

    For more information about OpenXML, you could refer the link below:
    # Welcome to the Open XML SDK 2.5 for Office
    https://msdn.microsoft.com/en-us/library/office/bb448854.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 29, 2016 1:17 AM