如何使用 VBA 在 MS-Word 2010/2013 中禁用保存、另存为按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16977599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:31:11  来源:igfitidea点击:

How to Disable Save, SaveAs button in MS-Word 2010/2013 using VBA

vba

提问by rsKRISH

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?

但这没有效果。有什么办法可以禁用这些按钮吗?

回答by rsKRISH

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 中禁用 Save 和 SaveAs,我使用了以下 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 Editorfor executing and testing this code. This linkprovides a nice training of how to use Custom UI Editor.

我使用自定义 UI 编辑器来执行和测试此代码。此链接提供了有关如何使用自定义 UI 编辑器的良好培训。

Thanks

谢谢

回答by Santosh

You can use Workbook_BeforeSaveevent.

您可以使用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

enter image description here

在此处输入图片说明