0

i am working with an excel file that auto updates when opened , i am using diagnostics process for opening it with c# and waiting for the auto chang

using (Process myProcess = Process.Start(@"C:\myfile.xlsx"))
            {

                myProcess.Refresh();

                Thread.Sleep(50000);

                myProcess.CloseMainWindow();
                myProcess.Close();
            }

the following lets the excel file be launched on my pc and waits for 50 seconds for the changes to happen then closes it , the only problem i am having that i need the excel to be closed for the rest of my code to work but it is prompting the DO YOU WANT TO SAVE CHANGES BEFORE CLOSING popup on my screen I want to know if i am missing something in my code that will allow the my excel document to be auto saved so the files gets closed without problems with the new changes, thank you all!

NexNex
  • 21
  • 6
  • Does this answer your question? [Disable Interop.Excel's Default Save Prompt on Close](https://stackoverflow.com/questions/42831230/disable-interop-excels-default-save-prompt-on-close) – Sinatr Nov 20 '20 at 13:41
  • You cannot prevent this behavior without using some sort of API (vsto, vba), but a possible workaround is to click "OK" in that dialog: try to activate window and send `{Enter}` key into it. – Sinatr Nov 20 '20 at 13:44

1 Answers1

0

I think you need to use Microsoft.Office.Interop.Excel.dll to help with you solving this requirement.

There is a Property in Application class, you can do like this

Microsoft.Office.Interop.Excel.Application excelDoc= new Microsoft.Office.Interop.Excel.Application();
excelDoc.DisplayAlerts = false;
Ce Guo
  • 21
  • 2