{"id":2140,"date":"2026-06-22T16:15:03","date_gmt":"2026-06-22T08:15:03","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2140"},"modified":"2026-03-28T08:00:02","modified_gmt":"2026-03-28T08:00:02","slug":"how-to-use-applicationmaxchange-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationmaxchange-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.MaxChange in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Application.MaxChange property in Excel VBA is used to set or return the maximum amount by which cell values can change during an iterative calculation, such as when using circular references with the iteration feature enabled. In xlwings, this property can be accessed through the Application object, allowing Python scripts to control Excel&#8217;s iterative calculation settings programmatically. This is particularly useful for financial modeling, engineering simulations, or any scenario where iterative solutions are required, as it helps define convergence criteria to prevent infinite loops.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>MaxChange determines the threshold for changes in cell values between iterations. When Excel performs iterative calculations, it continues recalculating until either the maximum iterations limit is reached or the change in all cell values is less than both MaxChange and MaxIterations settings. By adjusting MaxChange, you can fine-tune the precision of iterative results, balancing accuracy with calculation speed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, the MaxChange property is accessed via the Application object. The syntax is straightforward:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app = xw.App() # Connect to an Excel instance\nmax_change_value = app.api.MaxChange # Get the current MaxChange value\napp.api.MaxChange = new_value # Set a new MaxChange value<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>app<\/code> is an xlwings App object representing the Excel application. The <code>.api<\/code> attribute provides access to the underlying Excel object model, allowing direct interaction with properties like MaxChange. The property accepts and returns a float value, representing the maximum change tolerance. For example, setting it to 0.001 means iterations will stop when cell value changes are less than 0.001.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters and Values:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Value Type:<\/strong> Float (e.g., 0.001, 0.0001). It must be a positive number; setting it to 0 or negative may cause errors or unexpected behavior.<\/li>\n\n\n\n<li><strong>Default Value:<\/strong> In Excel, the default is 0.001, but this can vary based on user settings or workbook configurations.<\/li>\n\n\n\n<li><strong>Interaction with Other Settings:<\/strong> MaxChange works in conjunction with MaxIterations (accessible via <code>app.api.MaxIterations<\/code>). Iterations stop when either the maximum number of iterations is reached or the change in values is below MaxChange.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><br>Below are practical xlwings API examples demonstrating how to use MaxChange in Python scripts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Retrieving the Current MaxChange Value:<\/strong><br>This example connects to an active Excel instance and prints the current MaxChange setting.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n# Connect to the active Excel application\napp = xw.apps.active\ncurrent_max_change = app.api.MaxChange\nprint(f\"Current MaxChange value: {current_max_change}\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Setting MaxChange for Iterative Calculations:<\/strong><br>Here, we set MaxChange to a more precise value and enable iterative calculations by adjusting related properties.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App() # Start a new Excel instance\n# Configure iterative calculation settings\napp.api.Iteration = True # Enable iteration\napp.api.MaxIterations = 100 # Set maximum iterations\napp.api.MaxChange = 0.0001 # Set tighter change tolerance\nprint(\"MaxChange updated to 0.0001 for higher precision.\")\n# Open a workbook and perform calculations (e.g., with circular references)\nwb = app.books.add()\nws = wb.sheets&#91;0]\nws.range(\"A1\").formula = \"=B1+1\" # Example circular reference setup\nws.range(\"B1\").formula = \"=A1*0.5\"\nwb.save(\"iterative_example.xlsx\")\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Resetting MaxChange to Default:<\/strong><br>This script resets MaxChange to Excel&#8217;s typical default value.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.apps.active\napp.api.MaxChange = 0.001\nprint(\"MaxChange reset to default 0.001.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Application.MaxChange property in Excel VBA is used to set or return the maximum amount by which&#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-2140","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2140","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=2140"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2140\/revisions"}],"predecessor-version":[{"id":3273,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2140\/revisions\/3273"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}