Creating a workbook with named sheets

DChambers

Active Member
Joined
May 19, 2006
Messages
257
How would I create a workbook with two sheets named 'Blah1' and 'Blah2'?

I do not know how many sheets are created when I do workbooks.add and are there always going to be X number of sheets from computer to computer?

If only one sheet is created should I rename it and create another?

If three or more sheets are created what would be the best way to delete the unwanted sheets?

I must be missing something very simple.

Anyone?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Wrap some instructions around your workbooks.add method...

Code:
Sub Example()
    On Error GoTo Err_Example
    Dim SheetsInNewWorkbook As Long
    
    SheetsInNewWorkbook = Application.SheetsInNewWorkbook
    Application.SheetsInNewWorkbook = 2
    
    Workbooks.Add
    
    Application.SheetsInNewWorkbook = SheetsInNewWorkbook
Exit Sub
Err_Example:
Application.SheetsInNewWorkbook = SheetsInNewWorkbook
End Sub
 
Upvote 0
Tom,

Thanks for your code, it took a while to understand it.
Added names for worksheets and it works !!

Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top