如果未加载文档,请禁用自己的Word 2007加载项 [英] Disable Own Word 2007 Add-In If No Document Loaded

查看:91
本文介绍了如果未加载文档,请禁用自己的Word 2007加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Visual Studio 2010和.NET 3.5开发了Word 2007的应用程序级加载项.它所做的部分工作是使用

I've developed an application-level add-in for Word 2007 using Visual Studio 2010 and .NET 3.5. Part of what it does is use the

Globals.ThisAddIn.Application.Selection.Range

插入文本.

但是,当没有文档加载时,此代码将失败.我可以捕获异常或以编程方式检测当前是否打开了文档,但我认为必须有一种更简便的方法...

However, when there is no document loaded this code fails. I could catch the exception or programmatically detect whether a document was currently open, but I think there must be an easier way...

当Word 2007打开但未加载文档时,功能区上的大多数按钮都被禁用(即变灰).

When Word 2007 is open but no document is loaded, most of the buttons on the ribbon are disabled (that is, greyed out).

任何想法都可以实现吗? 加载项会挂接到事件中并相应地禁用其按钮吗? 如果是这样,这将是

Any idea how this is achieved? Will the add-ins hook into an event and disable their buttons accordingly? If so, would this be the

DocumentBeforeClose

事件,如果在没有文档的情况下以某种方式打开Word,这可能会有风险吗? (也就是说,没有加载文档,但尚未触发该事件.)

event, and could this be risky if Word is somehow opened without a document? (That is, there's no document loaded, but the event hasn't yet been triggered.)

提前谢谢!

更新: 好的,好像是在使用

UPDATE: OK, it seems like making use of the

getEnabled="MyMethod"

XML的属性可能是前进的方向,但这似乎仅适用于功能区上的单个控件,而不是整个功能区本身.

attribute of the XML might be the way forward, but this seems to only work for the individual controls on the Ribbon rather than the whole ribbon itself.

推荐答案

尝试改用DocumentChange事件(请参见

Try using the DocumentChange event instead (see my answer on this thread).

这篇关于如果未加载文档,请禁用自己的Word 2007加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆