Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ActiveX and JavaScript

Status
Not open for further replies.

grantwilliams

Programmer
Sep 8, 2003
66
AU
To all you JavaScript gurus out there!

Below is a copy of a script I'm working on that allows a user to export form values to a named Excel Spreadsheet and then allows the spreadsheet to be saved where the user chooses using the
Code:
GetSaveAsFilename()
function.

It WAS working... to a certain extent. When it was working, it wasn't saving as the file listed in the box, rather the "default" value referred to in the '
Code:
if (fname = "false")
' line. Now it just opens the spreadsheet, puts the values in and displays the Save As dialog box.

Can anyone see why this isn't working?

Thanks,

Grant

Code:
function cmdExport(form)
{
   var xls = new ActiveXObject ( "Excel.Application" );
   xls.visible = true;

   var x1FileName = "C:\\2003 Charges calculator.xls";
   var x1Book = xls.Workbooks.Open(x1FileName);

   xls.ActiveSheet.Cells(4,2).Value = form.numfiles.Value;
   xls.ActiveSheet.Cells(5,2).Value = form.numpages.Value;
   xls.ActiveSheet.Cells(6,2).Value = form.numdocs.Value;
   xls.ActiveSheet.Cells(7,2).Value = form.numexpages.Value;
   xls.ActiveSheet.Cells(8,2).Value = form.pagedel.Value;
   xls.ActiveSheet.Cells(9,2).Value = form.thirdparty.Value;

   var fname = xls.Application.GetSaveAsFilename("FOI Estimate.xls");
   if (fname="false"){
       fname="C:\\FOI Estimate.xls";
   }

   x1Book.SaveAs(fname);
   x1Book.Close;
   xls.visible = false;
   xls.Quit();
}
 
Hello grantwilliams,
Code:
if
(fname=="false")
Code:
{
       fname="C:\\FOI Estimate.xls";
   }
regards - tsuji
 
Thanks for the help. I found the solution after walking away from it for the night and coming back fresh. Below is the code that worked.

Code:
function cmdExport(form)
{
  var xls    = new ActiveXObject ( "Excel.Application" );
  xls.visible = true;

  var x1FileName = "C:\\2002 Charges calculator.xls";
  var x1Book = xls.Workbooks.Open(x1FileName);

  xls.ActiveSheet.Cells(4,2).Value = form.numfiles.value;
  xls.ActiveSheet.Cells(5,2).Value = form.numpages.value;
  xls.ActiveSheet.Cells(6,2).Value = form.numdocs.value;
  xls.ActiveSheet.Cells(7,2).Value = form.numexpages.value;
  xls.ActiveSheet.Cells(8,2).Value = form.pagedel.value;
  xls.ActiveSheet.Cells(9,2).Value = form.thirdparty.value;

  var fname = xls.Application.GetSaveAsFilename("FOI Estimate.xls", "Excel Spreadsheets (*.xls), *.xls");
  if (fname==""){
    fname="C:\\FOI Estimate.xls";
  }

  x1Book.SaveAs(fname);
  x1Book.Close;
  xls.visible = false;
  xls.Quit();

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top