{"id":2223,"date":"2026-08-03T07:18:09","date_gmt":"2026-08-02T23:18:09","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2223"},"modified":"2026-03-28T11:21:41","modified_gmt":"2026-03-28T11:21:41","slug":"how-to-use-applicationwindows-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationwindows-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.Windows in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Application.Windows<\/code> property in Excel&#8217;s object model provides a collection of all open workbook windows. In xlwings, this property is accessible through the <code>app<\/code> object, which represents the Excel application instance. It is particularly useful for programmatically managing and interacting with multiple workbook windows, such as iterating through them to perform actions like arranging, resizing, or closing windows based on specific conditions. This property is read-only and returns a <code>Windows<\/code> collection object, enabling developers to handle window-level operations efficiently within their automation scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br><code>app.api.Windows<\/code><br>Here, <code>app<\/code> is an instance of the xlwings <code>App<\/code> class, which connects to the Excel application. The <code>.api<\/code> attribute provides direct access to the underlying Excel object model, allowing you to use the <code>Windows<\/code> property. The returned collection can be indexed or iterated over, with each item representing a <code>Window<\/code> object corresponding to an open workbook window. For example, <code>app.api.Windows[0]<\/code> refers to the first window in the collection, typically the most recently activated window. Note that the order of windows in this collection may vary based on user interactions, so it&#8217;s advisable to reference windows by their <code>Caption<\/code> property (the window title) for more reliable access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Below is a practical xlwings code example that demonstrates how to use the <code>Application.Windows<\/code> property to list all open workbook windows and perform a simple action, such as arranging them in a tiled layout. This example assumes Excel is already running with multiple workbooks open.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel application instance\napp = xw.apps.active\n\n# Access the Windows collection via the .api attribute\nwindows = app.api.Windows\n\n# Print the Caption (title) of each open window\nprint(\"Open workbook windows:\")\nfor window in windows:\n    print(f\" - {window.Caption}\")\n\n# Arrange all windows in a tiled layout (Excel constant xlTiled = 1)\n# This organizes windows side-by-side without overlapping\nwindows.Arrange(Style=1) # Style 1 corresponds to xlTiled\n\n# Optionally, you can close a specific window by its Caption\n# For instance, close a window titled \"SalesData.xlsx\"\nfor window in windows:\n    if window.Caption == \"SalesData.xlsx\":\n    window.Close()\n    print(\"Closed SalesData.xlsx window.\")\n    break\n\n# Note: The Arrange method affects only visible windows. Hidden or minimized windows may not be rearranged.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.Windows` property in Excel&apos;s object model provides a collection of all open workboo&#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-2223","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2223","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=2223"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2223\/revisions"}],"predecessor-version":[{"id":3398,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2223\/revisions\/3398"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}