2012-10-25 44 views
3

我有下面的代码应该禁用另存为按钮在Word 2010中的方法在下面被称为在Document_Startup事件:禁用另存为按钮在Word 2010

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; 
} 

我期待保存作为按钮变灰,但它不是,它仍然起作用。我究竟做错了什么?

+0

这是否帮助http://msdn.microsoft.com/en-us/library/ee815851.aspx – JonH

回答

3

我想通了。我只需在下面的信息中添加一个Ribbon XML项目到项目中。我还需要禁用其他几个按钮:

 <?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> 
+0

你在哪里要加这个XML? – bsara

+0

另外,如果您需要可用'idMso'值的列表,请参阅以下网页:http://www.microsoft.com/en-us/download/details.aspx?id=3582(Office 2007),http: /www.microsoft.com/en-us/download/details.aspx?id=1574(Office 2010)或http://www.microsoft.com/en-us/download/details.aspx?id=36798( Office 2013) – bsara

+0

我在Windows窗体应用程序中遇到同样的问题。你可以让我知道我到底能在哪里添加这个xml文件以及在哪里引用它? –