c# - 如何抑制在 C# 中打开 word 文档时显示的 VIsual Basic "Macros are Disabled"对话框

标签 c# .net ms-word automation ms-office

我有一个非常烦人的问题。

我正在通过 c#/COM Interop (Word 2007) 打开一个 word 文档。我想阻止宏运行,因为其中一些可能会崩溃(旧文件缺少书签等)。

所以我运行以下代码来抑制所有可能弹出的对话框:

Word.ApplicationClass wordApplication = new Word.ApplicationClass();

wordApplication.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

wordApplication.ShowVisualBasicEditor = false;

wordApplication.AutomationSecurity = 
  Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;

Word.Document wordDoc = null;

然后当我执行以下代码时,我收到消息框“此项目中的宏已禁用”。

 wordDoc = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);

我需要抑制此消息,检测它是否正在显示并“确定”它,或者找到一种禁用启动宏的方法,而无需 VB 妨碍。

有什么想法吗?

最佳答案

我从来没能在 C# 中使用它,但在 VB.NET 中就没问题了。方法如下:How to open document that contains AutoOpen macro with PowerShell?

关于c# - 如何抑制在 C# 中打开 word 文档时显示的 VIsual Basic "Macros are Disabled"对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3778855/

相关文章:

vba - 在 Word VBA 中查找表格标题

vba - 为什么我看不到 Microsoft Forms 2.0 对象库?

c# - 什么样的循环执行更好?

c# - 有没有办法在 Windows 窗体中延迟事件处理程序(比如 1 秒)

c# - XML 比较,用于检查窗口应用程序是否相同或不同

c# - Microsoft.Office.Interop.Word 在代码中打开文档文件时出错

C# 遍历类属性

c# - 使用 GnuPG 从 C# 进行 PGP 加密

c# - 使用 JsonReader 而不是 JsonSerializer 时自定义 JsonConverter 不起作用

C# 代码片段不会自动导入命名空间