vba 如何禁用 Excel 2010 中的“保存并发送”(在文件功能区中(在 Office 2010 中称为后台)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17722987/
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 22:18:41  来源:igfitidea点击:

How do you disable "Save and send" in Excel 2010 (in the File ribbon (called backstage in Office 2010)?

vbaexcel-vbaexcel-2010ribbonribbonx

提问by Hubert

I have the following VBA marco running in Excel 2003, it blocks the Save, Save as, Save Workspace, Send To menus but I now need to do the same but for Excel 2010 ?

我在 Excel 2003 中运行了以下 VBA marco,它阻止了“保存”、“另存为”、“保存工作区”、“发送到”菜单,但我现在需要对 Excel 2010 执行相同操作?

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save Workspace...").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Send To").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("Format").Controls("Sheet").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File"). Controls("Save").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save Workspace...").Enabled = False

Application.CommandBars("Worksheet Menu Bar "). ").Controls("File").Controls("Send To").Enabled = False

Application.CommandBars("Worksheet Menu Bar").Controls("Format").Controls("Sheet").Enabled = False

There is a 'new menu' in Excel 2010 called "Save and send" (under the File ribbon) that I would like to also disable... How do you do this ? I'm searching for the equivalent to a line like this one:

Excel 2010 中有一个名为“保存并发送”的“新菜单”(在“文件”功能区下),我也想禁用它...你怎么做?我正在寻找相当于这样一行的内容:

'Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save & Send").Enabled = False

'Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save & Send").Enabled = False

Thank you for your help.

感谢您的帮助。

回答by David Zemens

For Ribbon UI example/documentation from Microsoft, here. They will recommend you use the CustomUI Editor.

有关 Microsoft 的 Ribbon UI 示例/文档,请点击此处。他们会建议您使用CustomUI Editor

Open your file (which must be an Excel 2007+ file extension like XLSX, XLSM, XLAM, etc) in the CustomUI Editor. Then use this XML in the editor:

在 CustomUI 编辑器中打开您的文件(必须是 Excel 2007+ 文件扩展名,如 XLSX、XLSM、XLAM 等)。然后在编辑器中使用这个 XML:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage>
    <tab idMso="TabShare" visible="false" enabled="false">
    </tab>
</backstage>
</customUI>

Save the file, and close the CustomUI Editor.

保存文件,然后关闭 CustomUI 编辑器。

Then, open your file. Go to the File/Backstage view and you should see that the Save and Sendtab has been removed:

然后,打开您的文件。转到 File/Backstage 视图,您应该看到该Save and Send选项卡已被删除:

screenshot of disabled TabShare

screenshot of disabled TabShare

Note:This has disabled the entire "Save & Send" tab from the backstage view. It should be possible using XML to fine-tune this, i.e., to enable the tab, but disable specific controls therein (e.g., maybe you only want to disable Send as Attachmentbut you want to leave the other options enabled, etc.) but I haven't quite worked out the XML hierarchy to disable onlythe specific Send As Attachmentcontrol.

注意:这已禁用后台视图中的整个“保存并发送”选项卡。应该可以使用 XML 对此进行微调,即启用选项卡,但禁用其中的特定控件(例如,您可能只想禁用Send as Attachment但希望启用其他选项等),但我没有t 完全制定了 XML 层次结构以禁用特定Send As Attachment控件。

Hope this helps!

希望这可以帮助!

Update from Comments

从评论更新

1) The user will find "normal" functionality when this file is closed, or when another file is Active. The UI customization only applies to the file which contains the Custom UI XML parts, so if you have multiple files open, only this file will be affected by the disabled Save & Sendtab.

1) 当此文件关闭或另一个文件处于活动状态时,用户将发现“正常”功能。UI 自定义仅适用于包含自定义 UI XML 部分的文件,因此如果您打开多个文件,则禁用Save & Send选项卡只会影响此文件。

2) Unfortunately, this is notcompatible with Excel 2003 or prior. The CustomUI/XML is not a part of the legacy XLS files, and as such, cannot be implemented in these versions. For 2003/prior versions of Excel, you will have to use the legacy CommandBarswhich can be controlled through VBA. It is relatively easy to put some VBA code that will check which version of Excel, and run a subroutine to disable certain CommandBar/Controls only if the user is in 2003 or prior versions.

2) 不幸的是,这与 Excel 2003 或更早版本兼容。CustomUI/XML 不是旧 XLS 文件的一部分,因此无法在这些版本中实现。对于 2003/以前版本的 Excel,您必须使用CommandBars可以通过 VBA 控制的旧版。放置一些 VBA 代码来检查 Excel 的版本,并CommandBar仅在用户使用 2003 或更早版本时才运行子例程来禁用某些/Controls是相对容易的。

If you try to save this down to an XLS file, you will receive a warning, indicating that this feature is incompatible with the file type:

如果您尝试将其保存为 XLS 文件,您将收到警告,表明此功能与文件类型不兼容:

CustomUI XML not compatible with XLS files

CustomUI XML not compatible with XLS files

Additionally, you cannot open an XLS file in the CustomUI Editor.

此外,您无法在 CustomUI 编辑器中打开 XLS 文件。

回答by user3679323

I have tried commands listed below and these are disabling the save and send menu in Excel 2010:

我已经尝试过下面列出的命令,这些命令禁用了保存和发送菜单Excel 2010

Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Send To").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save & Send").Enabled = False

回答by A.Wie

This commands worked for me

这个命令对我有用

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
    <command idMso="TabShare" enabled="false"/>
</commands> 
</customUI>