title: How to save Excel workbook to current user desktop by using javascript?
body: <p>I create workbook from web page by:</p>
  
  <pre><code>var thisTable = document.getElementById("mytable3").innerHTML;
         window.clipboardData.setData("Text", thisTable);
         var objExcel = new ActiveXObject ("Excel.Application");
         objExcel.visible = true;
         var objWorkbook = objExcel.Workbooks.Add();
         var objWorksheet = objWorkbook.Worksheets(1);
         objWorkbook.Worksheets(1).Activate;
         objWorksheet.name = "test";
         objWorksheet.Paste;
         objWorksheet.columns.autofit;
         window.clipboardData.setData("Text","");
         objWorkbook.Worksheets(1).SaveAs("%USERPROFILE%\\Desktop\\xxx.xls");
  </code></pre>
  
  <p>But for <code>objWorkbook.Worksheets(1).SaveAs("%USERPROFILE%\\Desktop\\xxx.xls");</code> — it doesn't save to desktop and gives this error:</p>
  
  <pre><code>SCRIPT1004: Microsoft Excel cannot access the file 'C:\Users\user\Documents\%USERPROFILE%\Desktop\B612F000'. There are several possible reasons:
  • The file name or path does not exist.
  • The file is being used by another program.
  • The workbook you are trying to save has the same name as a currently open workbook.
  </code></pre>