Word Automation-禁用警报 [英] Word Automation - Disable Alerts

查看:142
本文介绍了Word Automation-禁用警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动执行Word,所以我想取消所有警报.

I am automating Word, so I would like to suppress all alerts.

Word.Application word = new Word.Application();
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

我使用上面列出的代码,但是我不断从Word中获取消息-例如,文档已打开.有办法避免这种情况吗?如何抑制所有这些愚蠢的消息框?

I use the code listed above, but I keep getting messages from Word - e.g., the document is already open. Is there a way to avoid this? How to supress all those stupid messageboxes?

编辑:
考虑到所有答案,我想看门狗确实是唯一的选择.糟糕的是,最近几年没有任何改变.

EDIT:
Concider to all answers, I guess a watchdog is really the only option. To bad nothing has changed in last years.

可以在没有真正答案的情况下关闭线程.

Thread can be closed without a real answer.

推荐答案

您所发布的代码部分显然是正确的,但是我没有足够的能力来重现您描述的行为.但是...

The portion of code that you have posted obviously looks correct, but there isn't enough for me to reproduce the behavior that you describe. However...

我非常怀疑答案是您不能完全隐藏Word中的消息.它被设计为与用户互动的应用程序,DisplayAlerts设置有点像命中或命中的命题.某些错误看起来似乎可以从指定的警报设置中免除,并且仍然可以显示.例如,我以前看到过拼写和语法错误的行为.

I have a strong suspicion the answer is that you can't completely suppress messages in Word. It was designed as a user-interactive application, and the DisplayAlerts setting is a bit of a hit-or-miss proposition. Certain errors look like they might be exempted from the specified alert setting and be displayed anyway. For example, I've seen spelling and grammar errors behave like this before.

最好的办法是尝试预见可能发生的错误并避免产生这些错误.对于您的情况,您应该检查要打开的文档是否已经存在打开.我不确定为什么会首先产生此错误(您是在捕获错误并然后搜索该文档的现有实例以对其进行操作,还是您如何处理该错误?代码继续运行?),但是在开始执行相关代码之前插入一些保护子句应该很简单.

The best thing to do is try to anticipate the errors that may occur and avoid generating them. In your case, you should be checking to see if the document you're about to open is already open. I'm not sure why you'd ever be generating this error in the first place (are you catching the error and then searching for the existing instance of the document to operate on it, or how does your code continue running?), but it should be fairly straightforward to insert a few guard clauses before you start executing the relevant code.

这篇关于Word Automation-禁用警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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