I am automating Word, so I would like to suppress all alerts.
Word.Application word = new Word.Application();
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
I use the code listed above, but I keep getting messages from Word - e.g., the document is already open. Is there a way to avoid this? How to supress all those stupid messageboxes?
EDIT:
Concider to all answers, I guess a watchdog is really the only option. To bad nothing has changed in last years.
Thread can be closed without a real answer.
Click Options. Click Trust Center, and then click Trust Center Settings. Click Privacy Options. Under Privacy Options, select or clear Check Microsoft Office documents that are from or link to suspicious Web sites check box.
To set an alert on a document, select the file then click the Files tab, click Alert Me -> Set alert on this document. Note: if you don't see the Files tab, click the gear on the upper right corner and then turn on Ribbon.
Using a template with your Word Automation client has two significant advantages over building a document from nothing: You can have greater control over the formatting and placement of objects throughout your documents. You can build your documents with less code.
The portion of code that you have posted obviously looks correct, but there isn't enough for me to reproduce the behavior that you describe. However...
I have a strong suspicion the answer is that you can't completely suppress messages in Word. It was designed as a user-interactive application, and the DisplayAlerts
setting is a bit of a hit-or-miss proposition. Certain errors look like they might be exempted from the specified alert setting and be displayed anyway. For example, I've seen spelling and grammar errors behave like this before.
The best thing to do is try to anticipate the errors that may occur and avoid generating them. In your case, you should be checking to see if the document you're about to open is already open. I'm not sure why you'd ever be generating this error in the first place (are you catching the error and then searching for the existing instance of the document to operate on it, or how does your code continue running?), but it should be fairly straightforward to insert a few guard clauses before you start executing the relevant code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With