{"id":2200,"date":"2026-07-22T16:13:16","date_gmt":"2026-07-22T08:13:16","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2200"},"modified":"2026-03-28T10:37:49","modified_gmt":"2026-03-28T10:37:49","slug":"how-to-use-applicationtemplatespath-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationtemplatespath-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.TemplatesPath in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Excel, the Application object serves as the top-level object representing the entire Excel application. Among its many members, the TemplatesPath property is a read\u2011only property that returns the full path to the folder where Excel stores its template files. This is useful when you need to programmatically locate the default template directory, for example to save a custom template or to list available templates. In xlwings, you can access this property through the Application object, which is exposed via the <code>app<\/code> object when you have an active connection to Excel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The xlwings API syntax for accessing the TemplatesPath property is straightforward. Since it is a property, you simply reference it without parentheses. The general format is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.TemplatesPath<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>app<\/code> is an instance of the xlwings <code>App<\/code> class, which corresponds to the Excel Application object. The <code>.api<\/code> attribute provides direct access to the underlying Excel object model, allowing you to call native Excel properties and methods. The TemplatesPath property returns a string representing the full directory path. No parameters are required because it is a read\u2011only property.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if you want to retrieve the default templates path and print it, you would use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance or start a new one\napp = xw.apps.active\n\n# Get the TemplatesPath\ntemplates_folder = app.api.TemplatesPath\nprint(f\"The default templates path is: {templates_folder}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This code snippet first imports xlwings and then connects to the currently active Excel application. By accessing <code>app.api.TemplatesPath<\/code>, it retrieves the path and prints it. The output might look like <code>C:\\Users\\[Username]\\AppData\\Roaming\\Microsoft\\Templates\\<\/code> on Windows or a corresponding path on macOS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another practical use case is to combine the TemplatesPath with other operations, such as saving a workbook as a template in the default location. For instance:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nimport os\n\napp = xw.apps.active\nwb = app.books.active\n\n# Get the templates path and define a new template file name\ntemplates_path = app.api.TemplatesPath\nnew_template_name = \"MyCustomTemplate.xltx\"\nfull_path = os.path.join(templates_path, new_template_name)\n\n# Save the active workbook as a template in the default folder\nwb.save(full_path)\nprint(f\"Template saved to: {full_path}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Excel, the Application object serves as the top-level object representing the entire Excel applic&#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-2200","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2200","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=2200"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2200\/revisions"}],"predecessor-version":[{"id":3365,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2200\/revisions\/3365"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}