Search code examples
c#.netms-office

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


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.


Solution

  • 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"