How To Disable “The document being saved contains tracked changes” Word Dialog Using C#

谁说胖子不能爱 提交于 2020-02-23 10:33:05

问题


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.


回答1:


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"




回答2:


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);



来源:https://stackoverflow.com/questions/5083220/how-to-disable-the-document-being-saved-contains-tracked-changes-word-dialog-u

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!