Question posted 2011 · +4 upvotes
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.
Accepted answer +9 upvotes
I was able to figure out a programmatic solution by setting the following option in my code:
msDoc.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”
VBA Core objects referenced (5)
Application— Using events with the Application objectApplication— Working with Other ApplicationsInterop.Word— Exporting a Range to a Table in a Word DocumentInterop.Word— Using events with the Application object (Word)Microsoft.Office— Controlling One Microsoft Office Application from Another
Top ms-office Q&A (6)
- Detect whether Office is 32bit or 64bit via the registry +45 (2010)
- Installing Office Customization +31 (2009)
- What does the 'x' in the extensions aspx, docx, xlsx, etc. represent? +11 (2010)
- MSOFFICE MIME type verification +10 (2012)
- Problems with office automation in asp.net. I can use alternatives such as open-office, if I knew how +10 (2010)
- Can I embed an exe payload in a pdf, doc, ppt or any other file format? +10 (2010)
ms-office solutions on this site
.