问题描述
在Word中,我有一个打开的文档-我在另存为"对话框中导航到目录并选择一个现有文件.现在,当我单击保存"而不是取消"时,如果要覆盖/合并现有文档,则会收到消息.
In Word, I have an open document - I navigate in the 'Save As' dialog to a directory and select an existing file. When I now click 'Save' instead of 'Cancel', I get the message if I want to overwrite/merge the existing document.
是否可以在另存为"对话框中拦截保存"事件,以便我可以更改打开文档的文件名,从而抑制覆盖/合并消息?任何建议,我们将不胜感激!
Is it possible to intercept the 'Save' event in the 'Save As' Dialog so that I can change the file name of the open document, suppressing the overwrite/merge message? Any suggestions are greatly appreciated!
推荐答案
是的,完全可以拦截Word命令.在VBA时代,这就像创建一个与内部Word命令同名的宏一样容易.
Yes, it is totally possible to intercept Word commands. In the VBA days, it was as easy as creating a macro with the same name as the internal Word command.
在VSTO中,您需要将覆盖命令添加到Ribbon XML中,然后将回调添加到代码中.
In VSTO, you need to add the command overwrite to your Ribbon XML and then add a callback to your code.
MSDN中描述了整个过程: 在Office Fluent功能区上临时重新使用命令
The entire procedure is described in MSDN: Temporarily Repurpose Commands on the Office Fluent Ribbon
示例Ribbon XML (覆盖标准的保存"命令)
Sample Ribbon XML (overwriting the standard Save command)
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="OnLoad" >
<commands>
<command idMso="FileSave" onAction="mySave" />
</commands>
<ribbon startFromScratch="false">
<tabs>
<tab id="tab1" label="Repurpose Command Demo" >
<group id="group1" label="Demo Group">
<toggleButton id="togglebutton1"
imageMso="AcceptInvitation"
size="large"
label="Alter Built-ins"
onAction="changeRepurpose" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
功能区回调
public void mySave(IRibbonControl control, bool cancelDefault)
{
MessageBox.Show("The Save button has been temporarily repurposed.");
cancelDefault = false;
}
这篇关于在Word“另存为"对话框中拦截“保存"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!