{"id":2171,"date":"2026-07-08T07:21:47","date_gmt":"2026-07-07T23:21:47","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2171"},"modified":"2026-03-28T09:33:18","modified_gmt":"2026-03-28T09:33:18","slug":"how-to-use-applicationrecordrelative-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationrecordrelative-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.RecordRelative in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Application.RecordRelative<\/code> property in Excel&#8217;s object model is a Boolean property that indicates whether the next macro recording will use relative references. In simpler terms, when <code>RecordRelative<\/code> is set to <code>True<\/code>, any actions you record (like selecting cells) will be stored relative to the initially selected cell. When set to <code>False<\/code> (the default), recordings use absolute references, meaning actions are tied to specific cell addresses (e.g., <code>Range(\"A1\")<\/code>). This property is primarily useful when you are programmatically controlling the macro recorder via VBA or, in the context of automation, when you need to check or set the recorder&#8217;s state. However, it&#8217;s important to note that <code>xlwings<\/code>, as a Python library, does not have a direct, dedicated wrapper for every single property like <code>RecordRelative<\/code>. Instead, you access it through the generic <code>api<\/code> property, which exposes the underlying COM object (Excel&#8217;s Application object).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Parameters in xlwings:<\/strong><br>The xlwings syntax to get or set this property is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.RecordRelative<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a read\/write property. It accepts and returns a Boolean value.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Get:<\/strong> <code>current_state = app.api.RecordRelative<\/code> retrieves the current setting (<code>True<\/code> for relative, <code>False<\/code> for absolute).<\/li>\n\n\n\n<li><strong>Set:<\/strong> <code>app.api.RecordRelative = True<\/code> sets the macro recorder to use relative references for the next recording.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important Considerations:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The <code>RecordRelative<\/code> property only affects the <em>next<\/em> macro recording session started via the Excel UI (e.g., Developer Tab > Record Macro) or via <code>Application.StartRecorder<\/code>. It does not affect existing macros or code.<\/li>\n\n\n\n<li>This is a very low-level, recorder-specific property. Most xlwings scripts perform actions directly without involving the macro recorder, so its utility in typical xlwings automation is limited. It might be used in scenarios where you are building a tool that needs to programmatically prepare Excel&#8217;s environment for user-driven macro recording.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 1: Checking the Current RecordRelative Setting<\/em><\/p>\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 RecordRelative state\nrecording_mode = app.api.RecordRelative\nprint(f\"Next macro will record with relative references: {recording_mode}\")\n# Output might be: Next macro will record with relative references: False<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 2: Setting RecordRelative to True<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Set the recorder to use relative references for the next macro\napp.api.RecordRelative = True\nprint(\"Macro recorder is now set to relative reference mode.\")\n# If a user now starts recording a macro via the Excel UI, their cell selections will be recorded relatively.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 3: Toggling the Setting Based on a Condition<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Toggle the current state\ncurrent_state = app.api.RecordRelative\napp.api.RecordRelative = not current_state\nprint(f\"Toggled RecordRelative from {current_state} to {app.api.RecordRelative}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.RecordRelative` property in Excel&apos;s object model is a Boolean property that indicat&#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-2171","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2171","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=2171"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions"}],"predecessor-version":[{"id":3319,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions\/3319"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}