{"id":2076,"date":"2026-05-21T16:57:15","date_gmt":"2026-05-21T08:57:15","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2076"},"modified":"2026-03-28T06:10:48","modified_gmt":"2026-03-28T06:10:48","slug":"how-to-use-applicationdeferasyncqueries-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationdeferasyncqueries-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.DeferAsyncQueries in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>DeferAsyncQueries<\/strong> property of the <strong>Application<\/strong> object in Excel is a Boolean value that controls whether asynchronous queries (such as those from Power Query or external data connections) are deferred during the workbook&#8217;s opening process. When set to <strong>True<\/strong>, Excel postpones the execution of these queries until after the workbook has fully opened, which can significantly improve the initial load time, especially for workbooks with complex data connections. When set to <strong>False<\/strong> (the default), asynchronous queries run as usual during the opening sequence. This property is particularly useful for automating the opening of large workbooks in xlwings scripts, allowing you to manage performance and data refresh timing programmatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The property is accessed through the xlwings <code>App<\/code> object, which represents the Excel Application. The syntax is straightforward:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.DeferAsyncQueries<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This property is both readable and writable. You can assign a Boolean value (<code>True<\/code> or <code>False<\/code>) to it to change its state.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Get the current value:<\/strong> <code>current_state = app.api.DeferAsyncQueries<\/code><\/li>\n\n\n\n<li><strong>Set the value:<\/strong> <code>app.api.DeferAsyncQueries = True<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">There are no parameters for this property itself. Its behavior is simply toggled by the Boolean assignment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example:<\/strong><br>The following xlwings code demonstrates a practical use case. It opens a workbook with heavy external data connections, defers the queries to speed up the opening process, performs some other operations, and then manually triggers a refresh of all connections.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Start Excel application (visible for demonstration)\napp = xw.App(visible=True)\n\n# Enable deferral of asynchronous queries before opening the workbook\napp.api.DeferAsyncQueries = True\n\n# Open the target workbook\nwb = app.books.open(r'C:\\Path\\To\\Your\\Large_Workbook.xlsx')\n\n# At this point, the workbook is open, but queries are not yet run.\n# Perform other operations, such as reading static data or writing formulas.\nsheet = wb.sheets&#91;'Report']\nsummary_value = sheet.range('A1').value\nprint(f\"Initial summary value: {summary_value}\")\n\n# Now, disable deferral and refresh all external data connections.\napp.api.DeferAsyncQueries = False\nwb.api.RefreshAll()\n\n# Wait a moment for refresh to complete, then get updated data.\nimport time\ntime.sleep(5) # Simple pause; in production, consider checking query status.\nupdated_value = sheet.range('A1').value\nprint(f\"Refreshed summary value: {updated_value}\")\n\n# Save and close\nwb.save()\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **DeferAsyncQueries** property of the **Application** object in Excel is a Boolean value that co&#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-2076","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2076","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=2076"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2076\/revisions"}],"predecessor-version":[{"id":3177,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2076\/revisions\/3177"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}