Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

ms-office

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.

like image 659
CaMiX Avatar asked Feb 22 '11 19:02

CaMiX


2 Answers

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"

like image 146
CaMiX Avatar answered Oct 05 '22 13:10

CaMiX


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

like image 40
FrenkyB Avatar answered Oct 05 '22 12:10

FrenkyB