如何禁用“正在保存的文档包含跟踪的更改”使用 C# 的 Word 对话框

发布于 2024-10-18 13:02:01 字数 1150 浏览 1 评论 0原文

Microsoft.Office.Interop.Word.ApplicationClass msDoc = new Microsoft.Office.Interop.Word.ApplicationClass();
msDoc.Visible = false;
msDoc.Application.Visible = false;
msDoc.Documents.Open(ref docPath, ref UNKNOWN,
                     ref READ_ONLY, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN, ref UNKNOWN, ref UNKNOWN);
msDoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
msDoc.ActiveDocument.SaveAs(ref target, ref format,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN);

问题是,当执行“另存为”时,会出现一个对话框。我正在尝试以编程方式禁用该对话框,以便用户永远不必提供 Office/Word 的输入或配置。我正在编写的实用程序可能有数百次保存,因此弹出对话框并不好。

Microsoft.Office.Interop.Word.ApplicationClass msDoc = new Microsoft.Office.Interop.Word.ApplicationClass();
msDoc.Visible = false;
msDoc.Application.Visible = false;
msDoc.Documents.Open(ref docPath, ref UNKNOWN,
                     ref READ_ONLY, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                     ref UNKNOWN, ref UNKNOWN, ref UNKNOWN, ref UNKNOWN, ref UNKNOWN);
msDoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
msDoc.ActiveDocument.SaveAs(ref target, ref format,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
                            ref UNKNOWN, ref UNKNOWN);

The problem is that when SaveAs is executed a dialog appears. I'm trying to disable that dialog programmatically so that the user never has to provide input or configuration of Office/Word. The utility I'm writing could potentially have 100s of saves so a pop-up dialog isn't good.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味超标? 2024-10-25 13:02:01

我能够通过在代码中设置以下选项找到一个编程解决方案:

msDoc.Application.Options.WarnBeforeSavingPrintingSendingMarkup = false;

配置方面我发现您还可以通过进入以下位置禁用此 Office 功能:

Word 选项 -> 信任中心 -> 隐私选项 -> 取消选中“在打印、保存或发送包含跟踪更改或注释的文件之前发出警告”

I was able to figure out a programmatic solution by setting the following option in my code:

msDoc.Application.Options.WarnBeforeSavingPrintingSendingMarkup = false;

Configuration wise I found you could also disable this Office feature by going into:

Word Options->Trust Center->Privacy Options->Uncheck "Warn before printing, saving or sending a file that contains tracked changes or comments"

我早已燃尽 2024-10-25 13:02:01
msDoc.Options.WarnBeforeSavingPrintingSendingMarkup = false;

或者

Word选项->信任中心->隐私选项->取消选中“打印、保存或发送包含跟踪更改或注释的文件之前发出警告”

对我不起作用。

对我有用的是:

msDoc.ActiveWindow.Close(WdSaveOptions.wdDoNotSaveChanges);
msDoc.Options.WarnBeforeSavingPrintingSendingMarkup = false;

Or

Word Options-> Trust Center-> Privacy Options-> Uncheck "Warn before printing, saving or sending a file that contains tracked changes or comments"

Does not work for me.

What works for me is:

msDoc.ActiveWindow.Close(WdSaveOptions.wdDoNotSaveChanges);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文