Workbooks.Add with only 1 sheet in VBA

maatman

Board Regular
Joined
Oct 24, 2007
Messages
69
Hi,

I have the following code which creates a new workbook:

Workbooks.Add

The new workbook automatically contains 3 sheets, but I only want the workbook to have 1 sheet. I don't want to delete the other 2 sheets. I want that the new workbook just has 1 sheet.

Is this possible?

Regards
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Use Template:=xlWBATWorksheet.
 
Upvote 0
That's a bad idea - do you really want every new workbook you create to have 1 worksheet.:)
 
Upvote 0
Hi,

I have the following code which creates a new workbook:

Workbooks.Add

The new workbook automatically contains 3 sheets, but I only want the workbook to have 1 sheet. I don't want to delete the other 2 sheets. I want that the new workbook just has 1 sheet.

Is this possible?

Regards

Simply:

Workbooks.Add 1
 
Upvote 0
Simply:

Workbooks.Add 1



<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">Application.Workbooks.Add(1)</code></pre>
 
Upvote 0
Unless you are returning the Workbook to a variable (or using Call), there shouldn't be parentheses:
Code:
Application.Workbooks.Add 1

Either way, I'm not sure it was worth resurrecting a 4 year old thread for... ;)
 
Upvote 0
My "number of sheets in a new workbook" is set to 1, because I would rather insert a new worksheet when needed, than delete out two extra ones all the time, when I usually only want one. I then tried the "Workbooks.Add 1" code, with two sheets, and the "2" option created a chart sheet. So, rather than permanently messing with the setting, you can hold and then restore the value, while still creating a new workbook with as many sheets in it as you desire.

This example creates a new workbook with two sheets:

Code:
 Dim ShtsCnt As Integer
    With Application
      ShtsCnt = .SheetsInNewWorkbook
      .SheetsInNewWorkbook = 2
      Workbooks.Add
      .SheetsInNewWorkbook = ShtsCnt
    End With
 
Last edited:
Upvote 0
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">Application.Workbooks.Add(1)</code>
Thanks. It helped me creating a new workbook and assigning it to an object variable using SET keyword (i.e 2 in 1).
 
Upvote 0

Forum statistics

Threads
1,217,396
Messages
6,136,375
Members
450,006
Latest member
DaveLlew

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