-->

Disable the Save As Button in Word 2010

2019-02-18 13:28发布

问题:

I have the following code that should disable the Save As button in Word 2010. The method below is being called in the Document_Startup event:

private void DisableSaveAsButton()
{
    Object MenuBar = 40;
    Object FileMenu = 1;
    Object SaveAsButton = 5;
    var saveAsBtn = this.ThisApplication.CommandBars[MenuBar].Controls[FileMenu].accChild[SaveAsButton] as CommandBarButton;
    saveAsBtn.Enabled = false;
}

I am expecting the Save as Button to be grayed out, but it isn't and it still functions. What am I doing wrong?

回答1:

I figured it out. I just had to add a Ribbon XML item to the project with the following info below. I also needed to disable a few other buttons:

     <?xml version="1.0" encoding="UTF-8"?>
     <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
        onLoad="OnLoad" > 
        <commands> 
          <command idMso="FileSaveAs" enabled="false" />
          <command idMso="FileNewDefault" enabled="false"/>
          <command idMso="FileOpen" enabled="false"/>
          <command idMso="FileOpenRecentFile" enabled="false"/>
        </commands> 
     </customUI>