Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using excel application in my project. I am taking the excel template and filling that excel workbook and saving it into the new folder, it all works fine. After I am filling the excel application and saving that with the same file name it asks for: DO you want to replace the file?. If I click the no button it says that you want to make the changes to the Excel Template. Can anyone help me to solve this problem.Here is the code for saving the application:

excelWorkbook.SaveAs(@"D:\RiteFile\" + filename + ".xlsm");
               string path = @"D:\RiteFile\" + filename + ".xlsm";

               //excelApp.Visible = true;
               excelApp.UserControl = false;
               excelWorkbook.Close();
               excelApp.Workbooks.Close();
               excelApp.Quit();
               System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
               System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
               excelWorkbook = null;
               excelApp = null;
               System.Diagnostics.Process.Start(path);

           }
       }
       catch (Exception ex)
       {
           //UserUtil.Message(ex.Message, this);
           excelApp.UserControl = false;
           //excelWorkbook.Close();
           excelApp.Workbooks.Close();
           excelApp.Quit();
           //System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
           System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
           //excelWorkbook = null;
           excelApp = null;

       }


Thanks in Advance
Posted

may be readonly property is set to that ....
 
Share this answer
 
Hi,
before saving the excel file, add the following line
excelApp.DisplayAlerts = false;

Thanks
kannan
www.steadfastglobal.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900