{"id":2182,"date":"2026-07-13T15:08:11","date_gmt":"2026-07-13T07:08:11","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2182"},"modified":"2026-03-28T09:43:11","modified_gmt":"2026-03-28T09:43:11","slug":"how-to-use-applicationsheetsinnewworkbook-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationsheetsinnewworkbook-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.SheetsInNewWorkbook in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>SheetsInNewWorkbook<\/code> property of the <code>Application<\/code> object in Excel specifies the number of worksheets that are automatically included when a new workbook is created. This setting is a global option within the Excel application instance, allowing users or automation scripts to define a default sheet count, which can improve efficiency by avoiding the need to manually add sheets after workbook creation. In xlwings, this property is accessed through the <code>Application<\/code> object, providing a programmatic way to both retrieve and modify this default value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function is to control the default number of worksheets in new workbooks. This is particularly useful in automation scenarios where a consistent starting structure is required, or when preparing templates that need multiple sheets by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># To get the current setting\ncurrent_sheet_count = xw.apps&#91;0].api.SheetsInNewWorkbook\n\n# To set a new value\nxw.apps&#91;0].api.SheetsInNewWorkbook = new_count<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xw.apps[0]<\/code>: Represents the first (or a specific) Excel application instance controlled by xlwings. Use <code>xw.apps.active<\/code> for the active instance if multiple are open.<\/li>\n\n\n\n<li><code>.api<\/code>: Provides direct access to the underlying Excel object model (the COM API).<\/li>\n\n\n\n<li><code>SheetsInNewWorkbook<\/code>: The property being accessed. It expects an integer value.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameter\/Value Details:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Type:<\/strong> Read\/Write Property (Integer).<\/li>\n\n\n\n<li><strong>Value Range:<\/strong> The number must be an integer between 1 and 255, inclusive. Excel enforces these limits.<\/li>\n\n\n\n<li><strong>Default:<\/strong> Typically 1 in a standard Excel installation.<\/li>\n\n\n\n<li><strong>Persistence:<\/strong> This is an application-level setting in the current session. It is not permanently saved between Excel sessions unless configured within Excel&#8217;s options or set via a macro that runs on startup.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Retrieving the Current Default:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance\napp = xw.apps.active\n\n# Get the current default number of sheets\ndefault_sheets = app.api.SheetsInNewWorkbook\nprint(f\"New workbooks currently start with {default_sheets} sheet(s).\")\n# Output example: New workbooks currently start with 1 sheet(s).<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Changing the Default and Creating a Workbook:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Set the default to 3 worksheets\napp.api.SheetsInNewWorkbook = 3\n\n# Create a new workbook. It will now contain 3 worksheets automatically.\nnew_wb = app.books.add()\nprint(f\"New workbook has {len(new_wb.sheets)} sheets.\")\n# Output: New workbook has 3 sheets.\n\n# List the sheet names\nfor sheet in new_wb.sheets:\nprint(sheet.name)\n# Output: Sheet1, Sheet2, Sheet3<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Resetting to the Standard Default:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n# Reset to the common default of 1 sheet\napp.api.SheetsInNewWorkbook = 1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The `SheetsInNewWorkbook` property of the `Application` object in Excel specifies the number of work&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2182","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2182"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2182\/revisions"}],"predecessor-version":[{"id":3337,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2182\/revisions\/3337"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}