Disable the Save As Button in Word 2010

ぃ、小莉子 提交于 2019-12-01 07:22:53

问题


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>


来源:https://stackoverflow.com/questions/13074554/disable-the-save-as-button-in-word-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!