【问题标题】:Word Interop - Stop default program dialogWord 互操作 - 停止默认程序对话框
【发布时间】:2014-06-17 19:00:32
【问题描述】:

我在一个程序中使用 Microsoft Word Interop,我正在尝试创建一个 Word 应用程序,然后用它打开一个文档并读取它的书签数量。

问题是,当我在一台机器上创建 word 应用程序时,word 不是每种文档类型的默认程序(在测试时,我已将 .rtf 设置为使用写字板打开)我得到一个对话框,询问我是否我想更改 word 的默认程序设置。虽然此对话框仍处于打开状态,但我的代码正在尝试打开和访问文档的书签,这给了我一个 COMException 并显示消息“调用被被调用者拒绝”。

我仔细查看了 MSDN 的互操作文档,但没有找到任何有用的信息。

我的问题是:有什么方法可以在创建新应用程序时阻止此对话框出现?可能告诉 Word 不要检查这个?

谢谢

【问题讨论】:

  • 最后找到解决方案了吗?谢谢。
  • 嘿@EdwinYip,对不起,但我不记得我是如何解决这个问题的,如果我曾经解决过这个问题,我已经很久没有从事那个项目了

标签: c# vb.net ms-word office-interop com-interop


【解决方案1】:

试试这样的:

Microsoft.Office.Interop.Word.Application word= new Microsoft.Office.Interop.Word.Application();    
Document doc = word.Documents.Open(ref filename, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref obOpenAndRepair, ref oMissing, ref oMissing, ref oMissing);       
word.DisplayAlerts = WdAlertLevel.wdAlertsNone;

尚未对此进行测试,但应将 WdAlertlevel 设置为 none 以避免它显示警报。 WDAlertLevel 是 Microsoft.Office.Interop.Word 的枚举部分

【讨论】:

  • 这不起作用,因为一旦创建应用程序就会显示对话框。所以我什至没有机会在它出现之前设置警报级别。
猜你喜欢
  • 2012-01-16
  • 1970-01-01
  • 2011-10-18
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 2012-08-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多