Hi

I have a textbox and a button on a html page. On click of button I want to save the value in the textbox to a particular cell of the excel file

I have written the following code

var ExcelSheet = new ActiveXObject("Excel.Application");


        ExcelSheet.Workbooks.Open("D:\\TEST.XLS");
       
        // Make Excel visible through the Application object.
        ExcelSheet.Application.Visible = false;
       
        // Place some text in the first cell of the sheet.
        ExcelSheet.ActiveSheet.Cells(2,1).Value = document.forms[0].txtName.value ;
       
       
        // Save the sheet.
        ExcelSheet.Save();
        
        ExcelSheet.DisplayAlerts = false;
        // Close Excel with the Quit method on the Application object.
        ExcelSheet.Application.Quit();
        // Release the object variable.
        ExcelSheet = "";

Everything works fine. The value is stored in excel but when I click the button to save I am getting a message

"A file named 'RESUME.XLW' already exists in this location. "

I have also written

ExcelSheet.DisplayAlerts = false;

But still I am getting the message.

Why this message is coming and what is the way to supress it.

Kindly advice

Regards

Karan

Dani AI

Generated

Short answer: that dialog is coming from Excel trying to save a workspace file (the default workspace filename is "resume.xlw") rather than the workbook you think you are saving. Workspace files store window/layout information and Excel can prompt to overwrite them when a generic application-level save is issued. (support.microsoft.com)

Practical fixes (safe, ordered):

  • Save the specific Workbook object (Workbook.Save) instead of issuing a generic Application-level Save; that writes only the workbook you opened. (learn.microsoft.com)
  • Turn off prompts before saving (set the application alert flags) so Excel uses default responses; do this before calling Save, then restore the flags afterward. (learn.microsoft.com)
  • If you need a non-intrusive write that will not replace the open file in place, write a copy and then atomically replace the original (Workbook.SaveCopyAs or SaveAs with an explicit conflict-resolution choice). This is a reliable pattern for automation that overwrites files. (learn.microsoft.com)
  • Always close the workbook, call Application.Quit and release any COM/ActiveX references so Excel.exe does not hang in memory (this is the usual cause of the “Excel keeps running” / memory-leak symptoms). Follow Interop/COM cleanup best practices (release RCWs, GC, etc.). (stackoverflow.com)

Notes tied to prior replies: was correct that opening read-only avoids overwrite prompts but prevents saving; ’s observation (disable overwrite alerts before save) mirrors the DisplayAlerts/AlertBeforeOverwriting approach; and ’s memory-leak symptom is usually resolved by properly closing the workbook, quitting the Application and releasing COM references. Finally, automating Excel from a web page or server context has stability and security implications — Microsoft recommends against unattended/server-side Office automation for production services. (support.microsoft.com)

Recommended Answers

All 5 Replies

You can't supress it because it's a System alert! You are overwriting an existing file.

Try: ExcelSheet.Workbooks.Open("D:\\TEST.XLS", 2, true);

Hi

I have implemented your code but after that I am not able to save the excel file implicitly through the application, my system asks me to save the file explicitly.

Regards
Karan

Yeah that's also a system precaution measure...
I haven't been using this functionality for about 6-7 years now.
I'm not sure,
try ExcelSheet.SaveAs("D:\\TEST.XLS"); , that might supress the confirmation. Or simply close the document with quit command.

The .xlw exists when there are recovery versions that haven't been reconciled...I created a few to test. When I put the statement before the save, it stopped giving me the message.

xlApp.AlertBeforeOverwriting = False
xlApp.DisplayAlerts = False
xlApp.Save()

if you are getting this message you are lucky because .if you delete EXCEL.SAVE LINE.AND USE EXCEL.QUIT INSTEAD YOU WILL STILL GET A SAVE AS DILOGUE BOX .THE MESSAGE WONT COME BUT WHEN EVER YOU CLOSE YOUR PROJECT EXCEL WILL STILL BE HANGING IN MEMORRY.USING SAVEWORKSPACE BEFORE EXCEL.QUIT RELEASES EXCEL FROM MEMORRY.
tHIS IS A MEMMORY LEAK

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.