[英]How to Disable Save, SaveAs button in MS-Word 2010/2013 using VBA
Using VBA, I want to disable (or hide) the Save and SaveAs button shown in the File menu in MS Word 2013 so that the user cannot click them. 使用VBA,我想禁用(或隐藏)MS Word 2013的“文件”菜单中显示的“保存”和“另存为”按钮,以便用户无法单击它们。
I have tried disabling these buttons using this: 我尝试使用以下方式禁用这些按钮:
Word.CommandBars("File").Controls("&Save").Enabled = False
Word.CommandBars("File").Controls("&Save").Visible = False
But this has no effect. 但这没有效果。 Is there any way I can disable these buttons?
有什么方法可以禁用这些按钮吗?
Since version 2007 the "menu controls" are no longer controlled via the CommandBars object model.So, to control menu items I have to define Ribbon XML that has to be either incorporated into the document, or be loaded as part of an Add-in. 从2007版开始,“菜单控件”不再通过CommandBars对象模型进行控制。因此,要控制菜单项,我必须定义功能区XML,该功能区要么必须合并到文档中,要么作为外接程序的一部分加载。 。
To disable Save and SaveAs in Word 2010 I used this XML code : 要在Word 2010中禁用“保存”和“另存为”,我使用了以下XML代码:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="FileSave" enabled="false" />
<command idMso="FileSaveAsMenu" enabled="false" />
<command idMso="FileSaveAsWordDocx" enabled="false" />
<command idMso="FileSaveAsWordDotx" enabled="false" />
<command idMso="FileSaveAs" enabled="false" />
<command idMso="FileSaveAsWord97_2003" enabled="false" />
<command idMso="FileSaveAsPdfOrXps" enabled="false" />
<command idMso="FileSaveAsOtherFormats" enabled="false" />
<command idMso="FileSaveToDocumentManagementServer" enabled="false" />
<command idMso="SaveSelectionToQuickPartGallery" enabled="false" />
<command idMso="FrameSaveCurrentAs" enabled="false" />
<command idMso="FileSaveAsWordOpenDocumentText" enabled="false" />
</commands>
</customUI>
I used Custom UI Editor for executing and testing this code. 我使用自定义UI编辑器来执行和测试此代码。 This link provides a nice training of how to use Custom UI Editor.
该链接为如何使用自定义UI编辑器提供了很好的培训。
Thanks 谢谢
You can use Workbook_BeforeSave
event. 您可以使用
Workbook_BeforeSave
事件。
http://msdn.microsoft.com/en-us/library/office/ff840057.aspx http://msdn.microsoft.com/en-us/library/office/ff840057.aspx
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.