Such as read-only confirm, other alerts. What to do with these popups? Or ignore them?
5 Answers
See my answer here.
Basically, you disable all alerts via the "Display Alerts" method:
Microsoft.Office.Interop.[OFFICE_APP].Application app = new Microsoft.Office.Interop.[OFFICE_APP].Application();
app.DisplayAlerts = false;
where [OFFICE_APP] is the name of the Office program you're using, such as Word, Excel, etc.
-
3I have set this, but there also a popups for read-only confirm box etc. – Bruce Dou Apr 08 '11 at 04:29
-
1Is the read-only confirmation box your main concern? If so, have you tried opening the document with ReadOnly set to false and/or IgnoreReadOnlyRecommended set to true in the open() method? See here for what I'm referring to: [Workbooks.Open](http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.open(v=office.11).aspx) – dotNetkow Apr 08 '11 at 14:58
-
9As of Interop 2013 You can not use true or false, instead use Word.WdAlertLevel.wdAlersNone / ... – CantGetANick Sep 09 '13 at 08:28
-
@dotNetkow i have set the readonly proerty to true after that the code stop working :( – user3217843 Nov 24 '14 at 12:52
-
@user3217843 are you using 2013? see CantGetANick's response above. Different value to use. – dotNetkow Nov 24 '14 at 16:47
-
@dotNetkow i am using word 2010. – user3217843 Nov 25 '14 at 03:48
-
1You're great! I read dozens of non helpful answers, and had to waste a lot of precious time, before eventually finding your answer... – Ofer Sep 25 '16 at 14:38
-
@CantGetANick I used your solution and used Document.OpenNoRepairDialog too, to open the document, but still prompt appears. – Aniket Bhansali Dec 12 '17 at 07:35
-
@AniketBhansali I have no other solution :) Good luck – CantGetANick Feb 09 '18 at 12:31
-
Microsoft Word The last time you opened 'Sample.docx', it caused a serious error. Do you still want to open it? I get above message and my program stop working. Have you got anything similar. – Hemanth Bidare Aug 23 '19 at 12:02
-
@BruceDou Do make sure that you `enable` the `DisplayAlerts` back after your code so it's not disabled for other tasks where you may want usera to be warned before taking any actions where warning is necessary. – nam Nov 24 '19 at 00:03
Here is another alternative to prevent the Security message asking you to allow macros.
I read this article from MSDN and figured out the following code:
Application wordApp = new Application()
{
Visible = false,
AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
};
Since a copy of the file is made before opening it I don't have to change the AutomationSecurity back to the default setting.

- 1,119
- 13
- 29

- 101
- 1
- 5
Adding a note: for some file formats (I tested .XLS, but probably others too) that are password protected, app.DisplayAlerts = false
will NOT bypass the password dialog.
In this situation, you can simply pass a fake password on open, which will throw an error. Catch it if you want.
var app = new Application();
app.DisplayAlerts = false;
var workbook = app.Workbooks.Open(filePath, "fakePassword"); // Bypasses dialog, throws error
In this situation the error thrown is:
System.Runtime.InteropServices.COMException: The password you supplied is not correct. Verify that the CAPS LOCK key is off and be sure to use the correct capitalization.

- 7,322
- 4
- 41
- 64
Dear "Uriel Fernandez" with his thought https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel._application.automationsecurity?view=excel-pia
directed me to another thought https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel._application.screenupdating?view=excel-pia#Microsoft_Office_Interop_Excel__Application_ScreenUpdating
So can try disabling it _Application.ScreenUpdating and ... "You won't be able to see what the code is doing, but it will run faster"
EDIT
Word.Application app = null;
try
{
app = new Word.Application();
app.Visible = false;
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
app.ScreenUpdating = false;
// work ...
}
catch {}
app.Quit();
if (app != null) Marshal.ReleaseComObject(app);

- 391
- 2
- 15
Try this:
Microsoft.Office.Interop.Word.Application appWord = new
Microsoft.Office.Interop.Word.Application();
appWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
This will disable the popups.

- 9,179
- 14
- 63
- 125

- 13
- 3
-
2What does this answer add on top of the already posted other answer? – Tomáš Hübelbauer Apr 15 '17 at 07:43
-