George
George

Reputation: 53

Prevent File Now Available Popup Excel using C#

I need to read some data from an Excel document using C#. After successfully reading the data, I am closing the Excel and releasing all the COM objects.

x1Appl.DisplayAlerts = false;
            x1Appl.AlertBeforeOverwriting = false;
            x1WorkBook.Close(true);
            x1Appl.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(x1Range);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(x1WorkSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(x1WorkBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(x1Appl);

However, I am getting a popup "File Now Available", which I am unable to handle even though I have set x1Appl.DisplayAlerts = false; File Now Available

I have found this solution in Stackoverflow: Solution using VBA But this is with VBA. Is there any way to avoid this popup using C#?

Upvotes: 0

Views: 858

Answers (1)

Trench Scientist
Trench Scientist

Reputation: 21

Consider this:

Excel.Workbook xlWrkBk = x1Appl.Workbooks.Open("Your workbook file path", ReadOnly: true, Notify: false);

Your post doesn't indicate how you're reading in the file, so I am assuming you're using the code above when answering your post and that a file path has already been established before executing this line. You referenced an answer in VBA above and if you notice the syntax is quite similar. Hope this will help, even though it's almost a year after you asked. If you already solved it, perhaps it will help others. Also make sure you have released all the open instances of Excel. If you have opened the workbook by storing it in an object or opened more than once elsewhere in your code, those instances will need to be closed too.

How to terminate C# based Excel Application instance?

Upvotes: 2

Related Questions