There are many times when you need more than three sheets in a workbook. But when you use Workbooks.Add, it creates a New Workbook with three sheets (default for Microsoft Excel). Later you will add (or delete) the sheets for your use.
Here is another way to solve the problem. Use the Application's SheetsInNewWorkbook property to set the default no. of worksheets
Sub Set_No_Of_Sheets()
' -----------------------------------------
' coded for vbadud.blogspot.com by shasur
' -----------------------------------------
MsgBox "No of sheets in a blank workbook is : " & Application.SheetsInNewWorkbook
' set the Workbook for One Sheet
Application.SheetsInNewWorkbook = 1
' Workbook with only one sheet will be added
Workbooks.Add
' Reset the Workbook for Five Sheets
Application.SheetsInNewWorkbook = 3
End Sub
Here is a way suggested by Jon Peltier, Microsoft Excel MVP (http://PeltierTech.com)
Workbooks.Add([Template])
Template is optional, but if you use one of these constants, it creates a workbook with a single sheet of the type defined by the contant: Many thanks Jon for your suggestion
Many thanks Jon for your valuable suggestion
xlWBATChart, xlWBATExcel4IntlMacroSheet, xlWBATExcel4MacroSheet, or
xlWBATWorksheet
This command then creates a workbook with a single worksheet:
Workbooks.Add xlWBATWorksheet
No comments:
Post a Comment