Not able to set Name of the workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Not able to set Name of the workbook


My Javascript code look like this
JSActiveXObj = new ActiveXObject("Excel.Application");
JSNewWorkbook = JSActiveXObj.Workbooks.Add();

This code is working fine.

but if i try to give a name to the workbook using this code
JSActiveXObj = new ActiveXObject("Excel.Application");
JSNewWorkbook = JSActiveXObj.Workbooks.Add("xyx");

Sometimes it works fine but most of the times it is giving error. :(

Any help will be highly appreciated.
 
You can't name a workbook in this way, Excel assigns the name in a list
Book1, Book2, etc. You only assign the name when you save it.

But it shouldn't matter, the variable JSNewWorkbook points at the workbook.
 
Thanks Bob for the message...

But in my scenario I am exporting some data from the application to the
Excel sheet on a button click.As i want to ask user to save the file anywhere
by opening file open dialog box. I dont want to hardcode the path.
For this reason, I am not saving the file in my code. I am just closing the
file and excel is automatically asking user about saving of the file.
JSNewWorkbook.Close(1); // i m passing one so that it will not show the
message asking if you want to save the changes or not

But the problem is that i want to show the name of the file based on some
numbers. Suppose we are exporting the details of the employee. I want to give
the file name based on employee number.
Is there any workaround?

--
thanks and regards,
mohit


Bob Phillips said:
You can't name a workbook in this way, Excel assigns the name in a list
Book1, Book2, etc. You only assign the name when you save it.

But it shouldn't matter, the variable JSNewWorkbook points at the workbook.
 
Back
Top