如何抑制 VIsual Basic“宏已禁用”消息在 C# 中打开 Word 文档时显示的对话框
我有一个非常烦人的问题。
我通过 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 的方法。
有什么想法吗?
I have a really annoying problem.
I am openign a word document via c# / COM Interop (Word 2007). I want to prevent the Macros from Running as some of them may crash (older files with missing bookmarks etc.).
So I run the following code to suppress all the dialogs that may pop up:
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;
When I then execute the following code, I get the message box "Macros in this Project are Disabled".
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);
I need to either suppress this message, dettect if it is being shown and "ok" it or find a way of disableing startup macros without VB getting in the way.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从来无法让它在 C# 中工作,但在 VB.NET 中却没问题。操作方法如下:如何使用 PowerShell 打开包含 AutoOpen 宏的文档?
I never could get this to work with C#, but with VB.NET it was fine. Here's how to do it: How to open document that contains AutoOpen macro with PowerShell?
本文可能会有所帮助。我不确定你如何将其转换为 C#。
VBA 代码:
我不知道这是否会禁用“此项目中的宏已禁用”消息。
This article might help. I'm not sure how you'd translate it to C#.
VBA code:
I don't know if this will disable the "Macros in this Project are Disabled" message.