ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create new workbook and new worksheet and close. Worksheet not saved (https://www.excelbanter.com/excel-programming/431568-re-create-new-workbook-new-worksheet-close-worksheet-not-saved.html)

Patrick Molloy

Create new workbook and new worksheet and close. Worksheet not saved
 
don't confuse sheet save with workbook save. sheets are part of the workbook
so if wb is your workbook object and ws is a worksheet object
then
set ws = wb.worksheets.add()
will set ws to the worksheet object which has been created in the workbook
so
wb.save true
will save the workbook and thus all sheets. you don't need a ws.saveas
method as well


"Patrick" wrote in message
...
Hi,

I have scenario that users may give a filename and sheetname and both
are
not exiting. So I will create workbook by

Workbook.SaveAs(newWorkbookFullFileName, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlNoChange,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);

and then the sheet by

Sheet.SaveAs(worksheet.Workbook.Name, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value);


After that, users may close the appliation and I will do:


if (!Workbook.Saved)
{
Workbook.Save();
}

Workbook.Close(true, Missing.Value, Missing.Value);
App.Quit();


But when I use Excel to check the content of the file, the sheet
supposes to
be created as "SheetTest" is not there in the newly created workbook.
Am I
missing anything?

Thanks
Patrick




All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com