New WorkBook With Specified Number of Sheets

F

Faraz A. Qureshi

Sure would oblige if the proper complete syntax is provided in respect of
Creating a New Workbook with a specified number of sheets.

Thanx in advance!
 
P

p45cal

Faraz said:
Sure would oblige if the proper complete syntax is provided in respec
of
Creating a New Workbook with a specified number of sheets.

Thanx in advance!

From Help:
****************************
Creates a new workbook. The new workbook becomes the active workbook
Returns a Workbook object.

expression.Add(Template)
expression Required. An expression that returns a Workbooks object.

Template Optional Variant. Determines how the new workbook i
created. If this argument is a string specifying the name of an existin
Microsoft Excel file, the new workbook is created with the specifie
file as a template. If this argument is a constant, the new workboo
contains a single sheet of the specified type. Can be one of th
following XlWBATemplate constants: xlWBATChart
xlWBATExcel4IntlMacroSheet, xlWBATExcel4MacroSheet, or xlWBATWorksheet
If this argument is omitted, Microsoft Excel creates a new workbook wit
a number of blank sheets (the number of sheets is set by th
*SheetsInNewWorkbook *property).
**************************

At its simplest:

Code
-------------------
Application.SheetsInNewWorkbook = 25
Workbooks.Add

-------------------

but that would mean future workbooks added would be in danger of eac
having 25 sheets so it might be an idea to restore the original value:

Code
-------------------
origSINW = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 25
Workbooks.Add
Application.SheetsInNewWorkbook = origSINW

-------------------

The other way is to set up a template with as many sheets as you wan
(along with anything thing else such as sheet names, macros etc. etc.
and save it, say, as 'mytemplate.xlt' , then use

Code
 
B

Benito Merino

Sure would oblige if the proper complete syntax is provided in respect of
Creating a New Workbook with a specified number of sheets.

Thanx in advance!

Hello.

One way is:

Sub newworkbook()
pastsheets = Application.SheetsInNewWorkbook
newsheets = 3
Application.SheetsInNewWorkbook = newsheets
Workbooks.Add
Application.SheetsInNewWorkbook = pastsheets

End Sub

Regards,

Benito
Barcelona
 
Top