none
How To Disable Save, Save As , Export buttons in MS-Word 2013 using VBA. RRS feed

  • Question

  • Hi Experts,

    I am using Office 2013. I want to disable Save, Save As, Export buttons in a Word Document using VBA . By 'Disable' I mean, user should not be able to click on these buttons. I have tried disabling these buttons using 

    Word.CommandBars("File").Controls("&Save").Enabled = False

    Word.CommandBars("File").Controls("&Save").Visible = False

    And same for "Save As" .But this has no effect on the document and I was still able to use Save and SaveAs buttons. How can I disable these buttons ?

    Another problem I am facing is with 'Export' button. The UI shows the Export button under "File" menu but when I iterate the File menu it shows no entry of 'Export'. VBA code I am using to iterate the File menu is :    

    Dim ctl As CommandBarControl
        Dim cmd As CommandBar
        Dim menuItems As String

        MyFile1 = "C:\tmp\outputFromWord.txt"
        fnum1 = FreeFile()
        Open MyFile1 For Output As fnum1

        Set cmd = CommandBars("File")

        For Each ctl In cmd.Controls
           menuItems = ctl.Caption + "  ----> " + ctl.DescriptionText
           Print #fnum1, menuItems
        Next

    Close #fnum1

    What am I doing wrong here.?

    Thanks

    rsKRISH

    Monday, June 10, 2013 11:15 AM

Answers

  • Hi rsKRISH

    Since version 2007 the "menu controls" are no longer controlled via the CommandBars object model. You have to define Ribbon XML that has to be either incorporated into the document, or be loaded as part of an Add-in. This is going to be something of a learning curve for you...

    I recommend you work through the information on this site, starting with the three-part article on customizing the Ribbon for Developers followed by the articles on the Backstage for Developers.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 11, 2013 6:58 PM
    Moderator
  • Hello,

    "Export" is not a button but a backstage tab: 

    What and where is Backstage view

    So to disable it (hide it) in XML file, it would be like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <backstage>
        <tab idMso="TabPublish" visible="false"/>
      </backstage>
    </customUI>

    Note that the idMso is "TabPublish".

    Excel 2010 does not have "Export" tab in Backstage view. Instead, it has "Save & Send" tab containing the two options of exporting files.

    You can find idMso for Backstage view tabs of Excel 2013 here: http://www.rondebruin.nl/win/s2/win005.htm

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 24, 2013 2:34 PM
    Moderator

All replies

  • Hi rsKRISH

    Since version 2007 the "menu controls" are no longer controlled via the CommandBars object model. You have to define Ribbon XML that has to be either incorporated into the document, or be loaded as part of an Add-in. This is going to be something of a learning curve for you...

    I recommend you work through the information on this site, starting with the three-part article on customizing the Ribbon for Developers followed by the articles on the Backstage for Developers.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 11, 2013 6:58 PM
    Moderator
  • Thanks Cindy.

    I realised that that Ribbon XML is to be defined to control the menu items. I have word add-in which is already using Ribbon XML to control the menu items in Word - 2010. Thanks for pointing this out. Now I can disable SaveAs and Save.

    But still I am facing one problem.I can see that"Export" is added to the File Menu in Word 2013. And to control this button its IdMso is required. From microsoft's site (URL:  http://www.microsoft.com/en-us/download/details.aspx?id=36798 ),  I've downloaded the xls files which contains control IDs. But there is no entry for 'Export' in these files.

    Is there anyway to control 'Export' ?

      


     

    Thursday, June 13, 2013 8:16 AM
  • Hello,

    "Export" is not a button but a backstage tab: 

    What and where is Backstage view

    So to disable it (hide it) in XML file, it would be like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <backstage>
        <tab idMso="TabPublish" visible="false"/>
      </backstage>
    </customUI>

    Note that the idMso is "TabPublish".

    Excel 2010 does not have "Export" tab in Backstage view. Instead, it has "Save & Send" tab containing the two options of exporting files.

    You can find idMso for Backstage view tabs of Excel 2013 here: http://www.rondebruin.nl/win/s2/win005.htm

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 24, 2013 2:34 PM
    Moderator